diff --git a/GellishDictionary/Formal language definition base-UTF-8-subset.csv b/GellishDictionary/Formal language definition base-UTF-8-subset.csv index 9adc735..ab722cc 100644 --- a/GellishDictionary/Formal language definition base-UTF-8-subset.csv +++ b/GellishDictionary/Formal language definition base-UTF-8-subset.csv @@ -204,7 +204,7 @@ 63;910036;"English";492014;"Gellish";491285;"statement";;1228;"can be an element of a";1004160;6066;"is a base phrase for";;1228;"conceptual collection relation of an individual thing";;;;;;1045;"facts about kinds of relations";"accepted";;"6-okt-99";"6-okt-99";"ISO 10303-221 modelling team";"ISO 10303-221:2002" 64;910036;"English";589830;"Gellish alternative";491285;"statement";;1228;"can be a collection with as element a";1004673;1986;"is an inverse phrase for";;1228;"conceptual collection relation of an individual thing";;;;;;1045;"facts about conceptual relations";"accepted";;"23-jun-00";"18-feb-10";"Andries van Renssen";"Andries van Renssen" 65;910036;"English";492014;"Gellish";491285;"statement";;1228;"can have as element a";1026682;1986;"is an inverse phrase for";;1228;"conceptual collection relation of an individual thing";;;;;;1045;"facts about conceptual relations";"accepted";;"18-feb-10";"18-feb-10";"Andries van Renssen";"Andries van Renssen" -66;910036;"English";193259;"ontology";491285;"statement";;1229;"qualitative aspect";1001309;1146;"is a kind of";;4947;"qualitative kind";"that is a kind of aspect with a particular qualitative or quantitative value that is intended to qualify aspects. It can be a particular value, or a range or a collection of explicit types (allowed values for individual aspects). Examples of qualitative aspects are: red";"is a qualitative kind that is a kind of aspect with a particular qualitative or quantitative value that is intended to qualify aspects. It can be a particular value, or a range or a collection of explicit types (allowed values for individual aspects). Examples of qualitative aspects are: red, dry and a piece of text (qualitative information). Examples of quantitative aspect are: '½', '3 kg' and '6 at the scale of Richter'.";;;;1049;"facts about concepts";"accepted";;"3-dec-98";"9-feb-04";"Andries van Renssen";"Andries van Renssen" +66;910036;"English";193259;"ontology";491285;"statement";;1229;"qualitative aspect";1001309;1146;"is a kind of";;4947;"qualitative kind";"that is a kind of aspect with a particular qualitative or quantitative value that is intended to qualify aspects. It can be a particular value, or a range or a collection of explicit types (allowed values for individual aspects). Examples of qualitative aspects are: red";"is a qualitative kind that is a kind of aspect with a particular qualitative or quantitative value that is intended to qualify aspects. It can be a particular value, or a range or a collection of explicit types (allowed values for individual aspects). Examples of qualitative aspects are: red, dry and a piece of text (qualitative information). Examples of quantitative aspect are: '1/2', '3 kg' and '6 at the scale of Richter'.";;;;1049;"facts about concepts";"accepted";;"3-dec-98";"9-feb-04";"Andries van Renssen";"Andries van Renssen" 67;910036;"English";193259;"ontology";491285;"statement";;1229;"qualitative value";1007440;1981;"is a synonym of";;1229;"qualitative aspect";;;;;;1049;"facts about concepts";"accepted";;"31-jan-03";"21-dec-12";"Andries van Renssen";"Andries van Renssen" 68;910036;"English";193259;"ontology";491285;"statement";;1229;"defined aspect";1007392;1981;"is a synonym of";;1229;"qualitative aspect";;;;;;1049;"facts about concepts";"accepted";;"3-dec-98";"9-feb-04";"Andries van Renssen";"Andries van Renssen" 71;910036;"English";193259;"ontology";491285;"statement";;1231;"conceptual binary relation between things of specified kinds";1004638;1146;"is a kind of";;4698;"conceptual relation between things of specified kinds";"that relates two kinds of things by a conceptual relation of a specified kind specifying that individual things of those kinds can have a possible relationship of a kind that is a relatization of the specified conceptual kind. A related kind can be either a conceptual or a qualitative (including quantitative) kind. Note that which kind of relation can be a realization of a conceptual kind of relation is specified separately.";;;;;1045;"facts about conceptual relations";"accepted";;"6-nov-02";"19-jul-13";"Andries van Renssen";"ISO 10303-221:2002" @@ -844,7 +844,7 @@ 831;910036;"English";192696;"business";491285;"statement";;640128;"time frame of occurrence";1640168;1146;"is a kind of";;4331;"intrinsic time aspect";"being a role of period in time indicating a period within which something happens. The time frame may be wider than the occurrence periode, with the duration of the happening.";"is a intrinsic time aspect being a role of period in time indicating a period within which something happens. The time frame may be wider than the occurrence periode, with the duration of the happening.";;;;553310;"facts about kinds of roles";"accepted";;"22-aug-02";"1-dec-05";"Andries van Renssen";"Shell Design and Engineering Practices" 832;910036;"English";192696;"business";491285;"statement";;640129;"date of occurrence";1007842;1146;"is a kind of";;640128;"time frame of occurrence";"being the role of a time period that indicates the period within which something occurs. Typically a date that is referred by a year, a month in the year and a day in the month.";"is a time frame of occurrence being the role of a time period that indicates the period within which something occurs. Typically a date that is referred by a year, a month in the year and a day in the month.";;;;553310;"facts about kinds of roles";"accepted";;"19-nov-02";"9-dec-03";"Fred Vonk";"Shell Design and Engineering Practices" 833;910036;"English";192696;"business";491285;"statement";;640129;"date of happening";1640172;1981;"is a synonym of";;640129;"date of occurrence";;;;;;553310;"facts about kinds of roles";"accepted";;"22-aug-02";"9-dec-03";"Andries van Renssen";"Shell Design and Engineering Practices" -834;910036;"English";193259;"ontology";491285;"statement";;730000;"anything";1026496;1981;"is a synonym of";;730000;"what can be thought of.";;;;;;1047;"facts about kinds of relations between individual things";"accepted";;"27-nov-08";"27-nov-08";"Andries van Renssen";"Andries van Renssen" +834;910036;"English";193259;"ontology";491285;"statement";;730000;"anything";1026496;1981;"is a synonym of";;730000;"what can be thought of.";"what can be thought of.";;;;;1047;"facts about kinds of relations between individual things";"accepted";;"27-nov-08";"27-nov-08";"Andries van Renssen";"Andries van Renssen" 835;910036;"English";191874;"physics";491285;"statement";;730019;"solid item";1007836;1146;"is a kind of";;160177;"material";"that is solid and has a defined shape. It can be a single item or a collection of items or an assembly of items.";;;;;1049;"facts about concepts";"accepted";;"15-apr-96";"13-mei-03";"Fred Vonk";"item peers" 836;910036;"English";193259;"ontology";491285;"statement";;730019;"thing";1001090;1981;"is a synonym of";;730019;"solid item";;;;;;1049;"facts about concepts";"accepted";;"21-mrt-01";"25-okt-12";"Andries van Renssen";"Epstle Core Model modelling team" 837;910036;"English";191874;"physics";491285;"statement";;730019;"solid physical object";1027347;1981;"is a synonym of";;730019;"solid item";;;;;;1049;"facts about concepts";"accepted";;"27-jun-12";"27-jun-12";"Andries van Renssen";"Andries van Renssen" diff --git a/Web-Communicator/Anything.py b/Web-Communicator/Anything.py index d40cc58..7fcf161 100644 --- a/Web-Communicator/Anything.py +++ b/Web-Communicator/Anything.py @@ -57,11 +57,31 @@ def __init__(self, uid, name, category=None): def add_name_in_context(self, name_in_context): ''' add name or alias to collection of names: - name_in_context = (languageUID, communityUID, naming_relationUID, name). + name_in_context = (languageUID, communityUID, naming_relationUID, name, descr). ''' if name_in_context not in self.names_in_contexts: self.names_in_contexts.append(name_in_context) + def add_must_phrase(self, name_in_context): + """ Test whether name_in_context is a phrase that starts with 'shall', + if yes, then add a base phrase or inverse phrase that starts with 'must'. + name_in_context = languageUID, communityUID, name, naming_relationUID, descr + """ + new_phrase = '' + phrase = name_in_context[2] + phrase_parts = phrase.split(' ') + # If phrase is an English phrase that starts with 'shall' + # then a new phrase is added in which shall is replaced by must + if name_in_context[0] == '910036' and len(phrase_parts) > 2 \ + and phrase_parts[0] == 'shall': + new_phrase = 'must' + phrase[5:] + new_name_in_context = name_in_context[:] + new_name_in_context[2] = new_phrase + if new_name_in_context not in self.names_in_contexts: + self.names_in_contexts.append(new_name_in_context) + naming_rel_uid = new_name_in_context[3] + return new_phrase + def add_relation(self, relation): ''' add relation object to collection of relations with self.''' if relation not in self.relations: @@ -192,3 +212,43 @@ def __repr__(self): return("Idea: {} lh_uid: {} ({}) {} rh_uid: {}". format(self.uid, self.lh_obj.uid, self.rel_type.uid, self.phrase_type_uid, self.rh_obj.uid)) + + +if __name__ == "__main__": + # Test + from SemanticNetwork import Semantic_Network + language_uid_en = '910036' # English + language_uid_nl = '910037' # Dutch + community_uid = '492014' # Gellish + test_phrases = {'1': 'rel', + '2': 'shall have as part a', + '3': 'shall be a part of a', + '4': 'must be a part of a'} + GUI_lang_index = 0 + net_name = 'Net' + gel_net = Semantic_Network(GUI_lang_index, net_name) + names = test_phrases + language_uid = language_uid_en + gel_net.lang_uid_dict[language_uid] = language_uid_en + naming_relation_uid = '6066' + base_naming_relation_uid = '6066' + inv_naming_relation_uid = '1986' + gel_net.total_base_phrases = [] + gel_net.total_inverse_phrases = [] + for uid in names: + name = names[uid] + obj = Anything(uid, name) + obj.category = 'kind of relation' + descr = 'something' + name_in_context = [language_uid, community_uid, name, naming_relation_uid, descr] + obj.add_name_in_context(name_in_context) + + new_phrase = obj.add_must_phrase(name_in_context) + + if naming_relation_uid == '6066': + gel_net.total_base_phrases.append(new_phrase) + naming_relation_uid = inv_naming_relation_uid + else: + gel_net.total_inverse_phrases.append(new_phrase) + naming_relation_uid = base_naming_relation_uid + print('Phrase/New phrase: {} / {}'.format(name_in_context, new_phrase)) diff --git a/Web-Communicator/Create_output_file.py b/Web-Communicator/Create_output_file.py index 13d667b..f9c3ec3 100644 --- a/Web-Communicator/Create_output_file.py +++ b/Web-Communicator/Create_output_file.py @@ -4,7 +4,8 @@ import json from rdflib import Graph, URIRef, RDFS # Namespace, Literal, RDF, BNode -from tkinter import filedialog +# from tkinter import filedialog +import remi.gui as gui from Bootstrapping import ini_out_path # from Expr_Table_Def import * @@ -59,7 +60,8 @@ def Open_output_file(expressions, subject_name, lang_name, serialization): else: header1 = ['Gellish', 'English', 'Version', '9.0', date, 'Results', 'about ' + subject_name] - res = 'Results-' + res = 'Query_results-' + ini_file_name = '' if serialization == 'csv': ini_file_name = res + subject_name + '.csv.csv' if serialization == 'xml': @@ -73,23 +75,30 @@ def Open_output_file(expressions, subject_name, lang_name, serialization): # Select file name and directory # Ini_out_path from Bootstrapping - title = serialization + ' files' - extension = '*.' + serialization - output_file = filedialog.asksaveasfilename(filetypes=((title, extension), - ("All files", "*.*")), - title="Enter a file name", - initialdir=ini_out_path, - initialfile=ini_file_name) - if output_file == '': +## title = serialization + ' files' +## extension = '*.' + serialization +## output_file = filedialog.asksaveasfilename(filetypes=((title, extension), +## ("All files", "*.*")), +## title="Enter a file name", +## initialdir=ini_out_path, +## initialfile=ini_file_name) + output_file_name = ini_file_name + if output_file_name == '': output_file = 'Results.' + serialization if lang_name == 'Nederlands': print('***De filenaam voor opslaan is blanco of the file selectie is gecancelled. ' - 'De file is opgeslagen met de naam ' + output_file) + 'De file met naam ' + output_file + ' is niet opgeslagen') else: print('***File name for saving is blank or file selection is cancelled. ' - 'The file is saved under name ' + output_file) - Save_expressions_in_file(expressions, output_file, header1, serialization) + 'The file with name ' + output_file + 'is not saved') + else: + Save_expressions_in_file(expressions, output_file_name, header1, serialization) + +def fileupload_on_success(widget, filename): + print('File upload success: ' + filename) +def fileupload_on_failed(widget, filename): + print('File upload failed: ' + filename) def Save_expressions_in_file(expressions, output_file, header1, serialization): '''Write expressions to an output file in an CSV or RDF serialization''' @@ -97,20 +106,20 @@ def Save_expressions_in_file(expressions, output_file, header1, serialization): if serialization == 'csv': # Save the result_expr expressions in a CSV file, preceeded by three header lines. try: - f = open(output_file, mode='w', newline='', encoding='utf-8') - fileWriter = csv.writer(f, dialect='excel', delimiter=';') + f = open(output_file, mode='a', newline='', encoding='utf-8') + file_writer = csv.writer(f, dialect='excel', delimiter=';') # Write header rows and expressions - fileWriter.writerow(header1) - fileWriter.writerow(expr_col_ids) - fileWriter.writerow(header3) + file_writer.writerow(header1) + file_writer.writerow(expr_col_ids) + file_writer.writerow(header3) for expression in expressions: - fileWriter.writerow(expression) + file_writer.writerow(expression) f.close() # Open the written file in a CSV viewer (e.g. Excel) - open_file(output_file) + # open_file(output_file) except PermissionError: print('File {} cannot be opened. Probably already in use'.format(output_file)) return @@ -151,6 +160,10 @@ def Save_expressions_in_file(expressions, output_file, header1, serialization): # Open written file in a viewer open_file(output_file) + output_file = gui.FileUploader('./', width=200, height=30, margin='10px') + output_file.onsuccess.connect(fileupload_on_success) + output_file.onfailed.connect(fileupload_on_failed) + def Convert_numeric_to_integer(numeric_text): ''' Convert a numeric string into integer value removing dots(.), commas(,) and spaces( ) diff --git a/Web-Communicator/Display_views.py b/Web-Communicator/Display_views.py index 038d18e..1dbad77 100644 --- a/Web-Communicator/Display_views.py +++ b/Web-Communicator/Display_views.py @@ -4,7 +4,7 @@ import remi.gui as gui from remi_ext import TreeTable, SingleRowSelectionTable # MultiRowSelectionTable -from tkinter import filedialog, Tk +## from tkinter import filedialog, Tk from Bootstrapping import ini_out_path, basePhraseUID, inversePhraseUID from Expr_Table_Def import lh_name_col, rel_type_name_col, rh_name_col, status_col, \ @@ -18,6 +18,7 @@ from Occurrences_diagrams import Occurrences_diagram from utils import open_file from Anything import Relation +from QueryViews import Query_view class Display_views(): """ Various models about object(s) @@ -27,7 +28,7 @@ class Display_views(): def __init__(self, gel_net, user_interface): self.gel_net = gel_net self.user_interface = user_interface - self.root = user_interface.root +## self.root = user_interface.root self.GUI_lang_index = user_interface.GUI_lang_index self.uid_dict = gel_net.uid_dict self.container = user_interface.container @@ -74,6 +75,7 @@ def __init__(self, gel_net, user_interface): self.kinds = ['kind', 'kind of physical object', 'kind of occurrence', 'kind of aspect', 'kind of role', 'kind of relation', 'number'] self.specialization_uids = ['1146', '1726', '5396', '1823'] + self.classif_uids = ['1225', '1588'] self.subs_head = ['Subtypes', 'Subtypen'] self.comp_head = ['Part hierarchy', 'Compositie'] @@ -103,6 +105,7 @@ def __init__(self, gel_net, user_interface): self.selected_obj = None self.modified_object = None self.modification = None + self.know_table = None def empty_models(self): """ Make models empty enabling the creation of new models.""" @@ -2305,6 +2308,9 @@ def Display_notebook_views(self): if len(self.expr_table) > 0: self.Define_and_display_expressions_view() + if len(self.network_model) > 0: + self.user_interface.views_noteb.select_by_name(self.network_name) + def Display_message(self, text_en, text_nl): if self.GUI_lang_index == 1: self.user_interface.log_messages.append(text_nl) @@ -2329,28 +2335,31 @@ def Define_network_view(self): """ Define a network sheet for display of network_model (a list of network rows) for display in a tab of Notebook. """ + self.row_values = [] + self.row_uids = [] network_text = ['Network of ', 'Netwerk van '] self.network_name = network_text[self.GUI_lang_index] + self.object_in_focus.name self.network_frame = gui.VBox(width='100%', height='80%', style={'overflow': 'auto', 'background-color': '#eeffdd'}) - self.user_interface.views_noteb.add_tab(self.network_frame, - self.network_name, self.tab_cb(self.network_name)) + self.user_interface.views_noteb.add_tab( + self.network_frame, self.network_name, self.tab_cb(self.network_name)) - net_button_text = ['Display network of left object', 'Toon netwerk van linker object'] - lh_button_text = ['Display details of left object', 'Toon details van linker object'] - rh_button_text = ['Display details of kind', 'Toon details van soort'] + net_button_text = ['Network of left object', 'Netwerk van linker object'] + lh_button_text = ['Details of left object', 'Details van linker object'] + rh_button_text = ['Details of kind', 'Details van soort'] + know_button_text = ['Add knowledge', 'Voeg kennis toe'] classif_button_text = ['Classify left individual object', 'Classificeer linker individueel object'] self.close_button_text = ['Close', 'Sluit'] self.network_button_row = gui.HBox(height=20, width='100%') - self.net_button = gui.Button(net_button_text[self.GUI_lang_index], width='20%', height=20) + self.net_button = gui.Button(net_button_text[self.GUI_lang_index], width='15%', height=20) self.net_button.attributes['title'] = 'Press button after selection of left hand object' self.net_button.onclick.connect(self.Prepare_lh_object_network_view) - self.lh_button = gui.Button(lh_button_text[self.GUI_lang_index], width='20%', height=20) + self.lh_button = gui.Button(lh_button_text[self.GUI_lang_index], width='15%', height=20) self.lh_button.attributes['title'] = 'Press button after selection of left hand object' self.lh_button.onclick.connect(self.Prepare_lh_network_object_detail_view) @@ -2358,6 +2367,12 @@ def Define_network_view(self): self.rh_button.attributes['title'] = 'Press button after selection of right hand object' self.rh_button.onclick.connect(self.Prepare_rh_network_object_detail_view) + self.know_button = gui.Button(know_button_text[self.GUI_lang_index], + width='15%', height=20) + self.know_button.attributes['title'] = \ + 'Press button after selection of left hand object to add an expression of knowledge' + self.know_button.onclick.connect(self.add_knowledge) + self.classif_button = gui.Button(classif_button_text[self.GUI_lang_index], width='20%', height=20) self.classif_button.attributes['title'] = \ @@ -2375,6 +2390,7 @@ def Define_network_view(self): self.network_button_row.append(self.net_button) self.network_button_row.append(self.lh_button) self.network_button_row.append(self.rh_button) + self.network_button_row.append(self.know_button) self.network_button_row.append(self.classif_button) self.network_button_row.append(self.close_network) self.network_frame.append(self.network_button_row) @@ -2405,12 +2421,27 @@ def tab_cb(self, tab_name): def Determine_table_row_values(self, widget, row, item): ''' Determine the values in the row that is selected in the table.''' + self.row = row self.row_widgets = list(row.children.values()) self.row_values = [] + self.row_uids = [] if len(self.row_widgets) > 0: + begin = False for widget in self.row_widgets: - self.row_values.append(widget.get_text()) - print('Selected row values:', self.row_values) + value = widget.get_text() + if begin is False: + if value != '': + self.row_values.append(value) + print('Value:', value) + self.row_uids.append(widget.uid) + begin = True + else: + self.row_values.append(value) + try: + self.row_uids.append(widget.uid) + except AttributeError: + pass + print('Selected row values:', self.row_values, self.row_uids) def Display_network_view(self): """ Display a network of all related things @@ -2418,7 +2449,7 @@ def Display_network_view(self): network_model = related_uid, focus_uid, focus_name, phrase, related_name, kind_uid, related_name, focus_name, kind_name. """ - # Display self.network_model rows in self.network_tree TreeView + # Display self.network_model rows in self.network_tree TreeTable parent_uids = [] remembered_name = '' sub_level = 0 @@ -2477,23 +2508,30 @@ def Display_network_view(self): if relation is False and parent_name != '': net_row_widget.uid = network_line[0] for index, field in enumerate(network_line[6:]): - row_item = gui.TableItem(text=field, - style={'text-align': 'left', - 'background-color': color}) + display_text = field if relation is False: # If row is not a relation while parent is a relation name # then replace relation name with remembered parent name strings = field.partition(' ') if strings[0] in parent_text: - row_item = gui.TableItem(text=remembered_name, - style={'text-align': 'left', - 'background-color': color}) + display_text = remembered_name + row_item = gui.TableItem(text=display_text, + style={'text-align': 'left', + 'background-color': color}) + if index == 0: + # Add the uid of the left hand object to the first widget + row_item.uid = network_line[0] + elif index == 1: + # Add the uid of the kind to the first widget + row_item.uid = network_line[1] + elif index == 2: + # Add the uid of the kind to the first widget + row_item.uid = network_line[5] + if relation is False: net_row_widget.append(row_item, field) elif index < 1: # Relation line: only the first field to be displayed net_row_widget.append(row_item, field) - if index == 0: - row_item.uid = network_line[0] self.network_tree.append(net_row_widget, child_name) if child_uid not in parent_uids: parent_uids.append(child_uid) @@ -2996,8 +3034,8 @@ def Define_expressions_view(self): self.tab_cb(self.expr_name)) details = ['Details of LH object', 'Details van linker object'] expr_context_text = ['Contextual facts', 'Contextuele feiten'] - save_on_CSV_file = ['Save on CSV file', 'Opslaan op CSV file'] - save_on_JSON_file = ['Save on JSON file', 'Opslaan op JSON file'] + save_on_CSV_file_text = ['Save on CSV file', 'Opslaan op CSV file'] + save_on_JSON_file_text = ['Save on JSON file', 'Opslaan op JSON file'] self.expr_button_row = gui.HBox(height=20, width='100%') @@ -3017,18 +3055,18 @@ def Define_expressions_view(self): context_button.onclick.connect(self.Contextual_facts) self.expr_button_row.append(context_button) - save_CSV_button = gui.Button(save_on_CSV_file[self.GUI_lang_index], + save_CSV_button = gui.Button(save_on_CSV_file_text[self.GUI_lang_index], width='15%', height=20) save_CSV_button.attributes['title'] = 'First select a row, the press this button ' \ 'for storing expressions on CSV file' - save_CSV_button.onclick.connect(self.Save_on_CSV_file) + save_CSV_button.onclick.connect(self.save_on_CSV_file) self.expr_button_row.append(save_CSV_button) - save_JSON_button = gui.Button(save_on_JSON_file[self.GUI_lang_index], + save_JSON_button = gui.Button(save_on_JSON_file_text[self.GUI_lang_index], width='15%', height=20) save_JSON_button.attributes['title'] = 'First select a row, the press this button ' \ 'for storing expressions on JSON file' - save_JSON_button.onclick.connect(self.Save_on_JSON_file) + save_JSON_button.onclick.connect(self.save_on_JSON_file) self.expr_button_row.append(save_JSON_button) self.close_expr = gui.Button(self.close_button_text[self.GUI_lang_index], @@ -3086,7 +3124,7 @@ def Prepare_expr_row_widget(self, row, uid, row_color): row_widget.append(row_item, field) return row_widget - def Save_on_CSV_file(self): + def save_on_CSV_file(self): """ Saving query results in a CSV file in Gellish Expression Format.""" import csv import time @@ -3102,49 +3140,64 @@ def Save_on_CSV_file(self): # Note: the r upfront the string (rawstring) is # to avoid interpretation as a Unicode string (and thus giving an error) # ini_out_path from bootstrapping - ini_file_name = 'QueryResults.csv' - outputFile = filedialog.asksaveasfilename(filetypes=(("CSV files", "*.csv"), - ("All files", "*.*")), - title="Enter a file name", - initialdir=ini_out_path, - initialfile=ini_file_name, - parent=self.expr_frame) - if outputFile == '': - outputFile = ini_file_name - self.Display_message( - 'File name for saving is blank or file selection is cancelled. ' - 'If generated, the file is saved under the name <{}>'. - format(outputFile), - 'De filenaam voor opslaan is blanco of the file opslag is gecancelled. ' - 'Indien de file is gemaakt, dan is hij opgeslagen met de naam <{}>'. - format(outputFile)) + ini_file_name = 'Query_results.csv' + # directory + basedir = os.path.dirname(ini_out_path) + if not os.path.exists(basedir): + os.makedirs(basedir) +## output_file_name = filedialog.asksaveasfilename( +## filetypes=(("CSV files", "*.csv"), +## ("All files", "*.*")), +## title="Enter a file name", +## initialdir=ini_out_path, +## initialfile=ini_file_name, +## parent=self.expr_frame) +## if output_file_name == '': +## output_file_name = ini_file_name +## self.Display_message( +## 'File name for saving is blank or file selection is cancelled. ' +## 'If generated, the file is saved under the name <{}>'. +## format(output_file_name), +## 'De filenaam voor opslaan is blanco of the file opslag is gecancelled. ' +## 'Indien de file is gemaakt, dan is hij opgeslagen met de naam <{}>'. +## format(output_file_name)) - queryFile = open(outputFile, mode='w', newline='') - fileWriter = csv.writer(queryFile, dialect='excel', delimiter=';') + output_file_name = ini_file_name + query_file = open(output_file_name, mode='w', newline='') + file_writer = csv.writer(query_file, dialect='excel', delimiter=';') # Save the expr_table results in a CSV file, including three header lines # Write the three header lines and then the file content from expr_table - fileWriter.writerow(header1) - fileWriter.writerow(expr_col_ids) - fileWriter.writerow(header3) + file_writer.writerow(header1) + file_writer.writerow(expr_col_ids) + file_writer.writerow(header3) for expression in self.expr_table: - fileWriter.writerow(expression) + file_writer.writerow(expression) - queryFile.close() + query_file.close() self.Display_message( - 'File {} is saved.'.format(outputFile), - 'File {} is opgeslagen.'.format(outputFile)) + 'File {} is saved.'.format(output_file_name), + 'File {} is opgeslagen.'.format(output_file_name)) + self.output_file = gui.FileUploader(basedir, width=200, height=30, margin='10px') + self.output_file.onsuccess.connect(self.fileupload_on_success) + self.output_file.onfailed.connect(self.fileupload_on_failed) # Open written file in Excel - open_file(outputFile) + open_file(output_file_name) - def Save_on_JSON_file(self): + def save_on_JSON_file(self): """ Saving query results in a JSON file in Gellish Expression Format.""" subject_name = 'Query results' lang_name = 'Nederlands' serialization = 'json' Open_output_file(self.expr_table, subject_name, lang_name, serialization) + def fileupload_on_success(self, widget, filename): + print('File upload success: ' + filename) + + def fileupload_on_failed(self, widget, filename): + print('File upload failed: ' + filename) + def Define_and_display_kind_view(self): # Destroy earlier kind_frame try: @@ -3920,10 +3973,10 @@ def Prepare_lh_object_network_view(self, widget): as the chosen object for display of a new network view and other views. """ - # tree_values = self.Determine_network_tree_values() - if len(self.row_widgets[0]) > 0: - chosen_object_uid = self.row_widgets[0].uid - print('uid:', chosen_object_uid) + # tree_values = self.Determine_table_row_values() + if len(self.row_uids) > 0: + chosen_object_uid = self.row_uids[0] + print('Chosen uid:', chosen_object_uid) # Build single product model (list with one element) obj_list = [] obj = self.uid_dict[chosen_object_uid] @@ -3937,42 +3990,173 @@ def Prepare_lh_network_object_detail_view(self, widget): in a selected network treeview row as the chosen object for display of details. """ - # tree_values = self.Determine_network_tree_values() + # row_values = self.Determine_table_row_values() if len(self.row_values) > 0: - chosen_object_uid = self.row_values[0] - self.Determine_category_of_object_view(chosen_object_uid, self.row_values) - self.Determine_category_of_object_view(chosen_object_uid, self.row_values) + # Debug print('Row values:', self.row_values) + chosen_object_uid = self.row_uids[0] + # Debug print('Lh object uid:', chosen_object_uid) + self.Determine_kind_of_object_view(chosen_object_uid) def Prepare_rh_network_object_detail_view(self, widget): """ Set the uid of the right hand object in a selected network treeview row as the chosen object for display of details. """ - # tree_values = self.Determine_network_tree_values() - if len(self.row_values) > 4: - chosen_object_uid = self.row_values[4] - self.Determine_category_of_object_view(chosen_object_uid, self.row_values) - - def Prepare_for_classification(self): - """ Find the selected left classifier object from a user selection - in the network that is displayed in the network_tree view. - When the classification button was used the taxonomy of the selected kind - is displayed and a search for a second classifier in the taxonomy - (the subtype hierarchy of the selected kind) is started. + # row_values = self.Determine_table_row_values() + if len(self.row_values) > 2: + chosen_object_uid = self.row_uids[2] + self.Determine_kind_of_object_view(chosen_object_uid) + + def add_knowledge(self, widget): + """ After the add_knowledge button is used, + find the selected left hand object from a user selected row with row_values. + Then open a window for adding the expression of knowledge + about the selected left hand object. + """ + # row_values and row_uids from self.Determine_table_row_values() + if len(self.row_values) > 0: + if self.row_values[2] == '' or self.row_values[2] == 'unknown': + self.Display_message( + 'Right hand kind of object is unknown.', + 'Rechter soort object is onbekend.') + else: + kind_uid = self.row_uids[2] + object_uid = self.row_uids[0] + self.add_knowledge_to_left_hand_object(object_uid, kind_uid) + else: + self.Display_message( + 'Select an item, then click the classification button ' + 'for classying the object', + 'Selecteer een object, click dan op de classifikatieknop ' + 'om het object te classificeren') + + def add_knowledge_to_left_hand_object(self, object_uid, kind_uid): + """ Generate expressions of knowledge about object(_uid), + list them in a knowledge table, + and add them to the semantic network. + """ + self.relator_obj = self.uid_dict[object_uid] + # Create a knowledge table(only the first time) + if self.know_table == None: + self.know_name = ['Specified knowledge', 'Gespecificeerde kennis'] + self.know_frame = gui.VBox(width='100%', height='80%', + style={'overflow': 'auto', + 'background-color': '#eeffdd'}) + self.know_frame.attributes['title'] = self.know_name[self.GUI_lang_index] + self.user_interface.views_noteb.add_tab( + self.know_frame, self.know_name[self.GUI_lang_index], + self.tab_cb(self.know_name[self.GUI_lang_index])) + # Add button row + self.know_button_row = gui.HBox(height=20, width='100%') + self.know_frame.append(self.know_button_row) + + self.delete_button_text = ['Delete selected row', 'Verwijder geselecteerde regel'] + self.delete_know = gui.Button(self.delete_button_text[self.GUI_lang_index], + width='15%', height=20) + self.delete_know.attributes['title'] = 'Press button when you want to remove this tag' + self.delete_know.onclick.connect(self.delete_row) + self.know_button_row.append(self.delete_know) + + self.close_know = gui.Button(self.close_button_text[self.GUI_lang_index], + width='15%', height=20) + self.close_know.attributes['title'] = 'Press button when you want to remove this tag' + self.close_know.onclick.connect(self.Close_tag, + self.user_interface.views_noteb, + self.know_name[self.GUI_lang_index]) + self.know_button_row.append(self.close_know) + + self.know_table = SingleRowSelectionTable( + width='100%', + style={'overflow': 'auto', 'background-color': '#eeffaa', + 'border-width': '2px', 'border-style': 'solid', + 'font-size': '12px', 'table-layout': 'auto', + 'text-align': 'left'}) + self.know_table.on_table_row_click.connect(self.Determine_table_row_values) + self.head_row = gui.TableRow(height=20, width='100%') + lh_head = ('Left hand object', 'Linker object') + rel_head = ('Kind of relation', 'Soort relatie') + rh_head = ('Right hand object', 'Rechter object') + uom_head = ('Unit of measure', 'Meeteenheid') + descr_head = ('Description', 'Omschrijving') + head = [(lh_head[self.GUI_lang_index], rel_head[self.GUI_lang_index], + rh_head[self.GUI_lang_index], uom_head[self.GUI_lang_index], + descr_head[self.GUI_lang_index])] + self.know_table.append_from_list(head, fill_title=True) + self.know_frame.append(self.know_table) + self.row = None + + # Determine objects for expression via query window + search_for = 'object' + self.know_view = Query_view(self.user_interface, search_for, self.relator_obj) + self.know_view.Define_query_window() + self.user_interface.views_noteb.select_by_name(self.know_view.search_name) + + def delete_row(self, widget): + if self.row is not None: + self.know_table.remove_child(self.row) + self.row = None + + def create_knowledge_expression(self): + """ Create a knowledge expression from selected options.""" + # Create knowledge row widget + self.know_row_widget = gui.TableRow(height=20, width='100%') + # Add relator object name to TableRow + # self.lh_obj = self.know_view.query.q_lh_obj + lh_obj_name = self.know_view.query.q_lh_name + lh_obj_name_widget = gui.TableItem(lh_obj_name) + self.know_row_widget.append(lh_obj_name_widget) + lh_obj_descr = self.know_view.full_def_widget.get_text() + + # Add rel_type name to TableRow + # self.rel_obj = self.know_view.query.q_rel_obj + rel_obj_name = self.know_view.query.q_rel_name # selected name + rel_obj_name_widget = gui.TableItem(rel_obj_name) + self.know_row_widget.append(rel_obj_name_widget) + + # Add rh_obj name to TableRow + # self.rh_obj = self.know_view.query.q_lh_obj + # Debug print('Rh_obj.name:', self.rh_obj.name) + rh_obj_name = self.know_view.query.q_rh_name + rh_obj_name_widget = gui.TableItem(rh_obj_name) + self.know_row_widget.append(rh_obj_name_widget) + + # Add uom name to TableRow + # self.rh_obj = self.know_view.query.q_lh_obj + # Debug print('Rh_obj.name:', self.rh_obj.name) + uom_obj_name = self.know_view.query.q_uom_name + uom_obj_name_widget = gui.TableItem(uom_obj_name) + self.know_row_widget.append(uom_obj_name_widget) + + # If the new kind of relation is a specialization or classification + # Then add a textual description to the left hand object + if self.know_view.query.q_rel_uid in self.specialization_uids \ + or self.know_view.query.q_rel_uid in self.classif_uids: + is_a = ['is a ', 'is een '] + full_def = is_a[self.GUI_lang_index] + rh_obj_name + ' ' + lh_obj_descr + full_def_widget = gui.TableItem(full_def) + self.know_row_widget.append(full_def_widget) + self.know_table.append(self.know_row_widget) + self.user_interface.views_noteb.select_by_name(self.know_name[self.GUI_lang_index]) + + def Prepare_for_classification(self, widget): + """ After the classification button is used, + find the classifying kind of the selected left hand individual object + from a user selection in the network that is displayed in the network_tree view. + Then the taxonomy of the selected kind is displayed + for searching for a second classifier in the taxonomy + (the subtype hierarchy of the selected kind). The aspects of the individual object are used to create selection criteria for the subtypes in the hierarchy. - The taxonomy of the selected kind is displayed for selection of the classifier. """ - # similar to def Prod_taxonomy(self, sel): - # tree_values = self.Determine_network_tree_values() + # row_values = self.Determine_table_row_values() if len(self.row_values) > 0: - if self.row_values[4] == '' or self.row_values[4] == 'unknown': + if self.row_values[2] == '' or self.row_values[2] == 'unknown': self.Display_message( 'Classifying kind of object is unknown.', 'Classificerende soort object is onbekend.') else: - kind_uid = str(self.row_values[4]) - individual_object_uid = str(self.row_values[0]) + kind_uid = self.row_uids[2] + individual_object_uid = self.row_uids[0] self.Classification_of_individual_thing(individual_object_uid, kind_uid) else: self.Display_message( @@ -4020,8 +4204,8 @@ def Classification_of_individual_thing(self, to_be_classified_object_uid, kind_u ## widget_name = widget.get_value() ## # Debug print('Selected for detail network:', widget_name, widget.uid) ## # self.selected_obj = self.gel_net.uid_dict[widget.uid] -## tree_values = [widget.uid, widget_name] -## self.Determine_category_of_object_view(widget.uid, tree_values) +## self.row_values = [widget.uid, widget_name] +## self.Determine_kind_of_object_view(widget.uid) ## def Determine_network_tree_values(self): ## """ Determine the values on a selected row in a network TreeTable.""" @@ -4039,29 +4223,29 @@ def Classification_of_individual_thing(self, to_be_classified_object_uid, kind_u ## 'Geen object gevonden. Selecteer eerst een rij, click daarna op een knop.') ## return tree_values - def Determine_category_of_object_view(self, chosen_object_uid, row_values): + def Determine_kind_of_object_view(self, chosen_object_uid): """ Determine kind of chosen object and as a consequence models and views.""" description_text = ['description', 'beschrijving'] obj_descr_title = ['Information about ', 'Informatie over '] - if chosen_object_uid != '': + if chosen_object_uid != '' and chosen_object_uid != 'unknown': self.selected_obj = self.uid_dict[str(chosen_object_uid)] # If info_kind is a description then display the destription in messagebox - if len(row_values) > 8 and row_values[8] in description_text: + if len(self.row_values) > 8 and self.row_values[8] in description_text: self.messagebox(obj_descr_title[self.GUI_lang_index] + self.selected_obj.name, self.selected_obj.description) else: self.Display_message( 'Display object details of: {}'.format(self.selected_obj.name), - 'Weergave van objectdetails van: {}'.format(self.selected_obj.name)) + 'Toon details van object: {}'.format(self.selected_obj.name)) if self.selected_obj.category in self.gel_net.categories_of_kinds: self.Define_and_display_kind_detail_view(self.selected_obj) else: self.Define_and_display_individual_detail_view(self.selected_obj) - - if len(self.info_model) > 0: - self.Define_and_display_documents() +## +## if len(self.info_model) > 0: +## self.Define_and_display_documents() def Kind_detail_view_left(self, widget): """ Find the selected left hand object from a user selection @@ -4610,6 +4794,13 @@ def Contextual_facts(self, widget): self.context_box.show(self.user_interface) + def Close_tag(self, widget, tabbox, ref_widget_tab_name): + ''' Close the tab in tabbox in widget with the specified tab_name''' + # tabbox.select_by_name(ref_widget_tab_name) + tabbox.remove_tab_by_name(ref_widget_tab_name) + if ref_widget_tab_name in self.know_name[self.GUI_lang_index]: + self.know_table = None + class User_interface(): def __init__(self): @@ -4634,7 +4825,7 @@ def __init__(self, name): if __name__ == "__main__": - root = Tk() +## root = Tk() user_interface = User_interface() gel_net = Semantic_network('name') views = Display_views(gel_net) @@ -4644,4 +4835,4 @@ def __init__(self, name): views.user_interface.Define_notebook() views.Display_notebook_views() - root.mainloop() +## root.mainloop() diff --git a/Web-Communicator/Gellish_file.py b/Web-Communicator/Gellish_file.py index 8cb2e0a..374bee6 100644 --- a/Web-Communicator/Gellish_file.py +++ b/Web-Communicator/Gellish_file.py @@ -66,7 +66,7 @@ def __init__(self, path_and_name, gel_net): Message(self.gel_net.GUI_lang_index, 'File name extension {} is not (yet) supported.'.format(name_ext[1]), 'Filenaam extensie {} wordt (nog) niet ondersteund.'.format(name_ext[1])) - self.extension = '' + self.extension = name_ext[1] else: # Allocate file extension to file self.extension = name_ext[1] @@ -453,7 +453,7 @@ def Import_expressions_from_Gellish_file(self, f, reader): # then append the dictionary with the terms available in the language column # Debug print('Col_ids',lang_name_col_id) for col_id in lang_name_col_id: - # Only for rows with a specialization and alias relation + # Only for rows with a specialization or alias relation if db_row[rel_type_uid_col] in self.gel_net.specialRelUIDs \ or db_row[rel_type_uid_col] in self.gel_net.alias_uids: # Check whether column value (name of object) is not blank, diff --git a/Web-Communicator/Query.py b/Web-Communicator/Query.py index 21c09e4..5a7ffbf 100644 --- a/Web-Communicator/Query.py +++ b/Web-Communicator/Query.py @@ -1,20 +1,10 @@ #!/usr/bin/python3 -# import sys -# import os -# import csv -# import sqlite3 -# import pickle -# from tkinter import * -# from tkinter.ttk import * - from Expr_Table_Def import intent_name_col, lh_uid_col, lh_name_col, phrase_type_uid_col, \ rel_type_uid_col, rel_type_name_col, rh_uid_col, rh_name_col, uom_uid_col, uom_name_col, \ rh_role_uid_col, rh_role_name_col, idea_uid_col -# from Anything import Anything, Object, Individual, Kind, Relation, RelationType from Bootstrapping import basePhraseUID, by_def_role_of_ind -# from GellishDict import GellishDict -from Create_output_file import Create_gellish_expression, Convert_numeric_to_integer, \ - Open_output_file +from Create_output_file import Create_gellish_expression, Convert_numeric_to_integer +# Open_output_file class Query: @@ -443,7 +433,7 @@ def Create_query_file(self): # subject_name = ['query_spec', 'vraagspecificatie'] file_lang_name = 'Nederlands' serialization = 'csv' - Open_output_file(self.gel_expressions, 'query', file_lang_name, serialization) + # Open_output_file(self.gel_expressions, 'query', file_lang_name, serialization) def Execute_query(self): """ Execute a query on the network to find the searched objects diff --git a/Web-Communicator/QueryViews.py b/Web-Communicator/QueryViews.py index 34e02f6..8e07eee 100644 --- a/Web-Communicator/QueryViews.py +++ b/Web-Communicator/QueryViews.py @@ -1,4 +1,3 @@ -# import os import remi.gui as gui from remi_ext import SingleRowSelectionTable, MultiRowSelectionTable from operator import itemgetter @@ -6,20 +5,22 @@ from Bootstrapping import is_called_uid from Expr_Table_Def import lh_uid_col, lh_name_col, lh_role_uid_col, rel_type_uid_col, \ rh_uid_col, rh_name_col, rh_role_uid_col, uom_name_col -# from Query import Query from Anything import Anything from Create_output_file import Convert_numeric_to_integer -# Create_gellish_expression, Open_output_file + class Query_view(): - ''' Defines a query window + """ Defines a query window for specification of searched/queries in the semantic network of dictionary, knowledge and information, including the display of a textual definition, synonyms and translations. - ''' - def __init__(self, gel_net, user_interface): - self.gel_net = gel_net + Args: + search_for = either 'subject' or 'object' or 'kind of relation'. + relator_obj = either None or lh_obj + """ + def __init__(self, user_interface, search_for, relator_obj=None): self.user_interface = user_interface + self.gel_net = user_interface.gel_net self.views = user_interface.views self.query = user_interface.query self.unknown_quid = user_interface.unknown_quid @@ -30,6 +31,8 @@ def __init__(self, gel_net, user_interface): self.GUI_lang_name = self.user_interface.GUI_lang_name self.GUI_lang_uid = self.user_interface.GUI_lang_uid self.GUI_lang_index = self.user_interface.GUI_lang_index + self.relator_obj = relator_obj + self.search_for = search_for # 'subject' or 'object' or 'kind of relation' self.cs = 'cs' # case sensitive - to search string self.fe = 'fi' # front end identical @@ -37,6 +40,7 @@ def __init__(self, gel_net, user_interface): self.lh_options = [] self.rh_options = [] self.rel_options = [] + self.uom_options = [] self.unknowns = [] # List of unkown objects that are denoted by an unknown in a query self.names_of_unknowns = [] self.unknown_kind = ['unknown kind', 'onbekende soort'] @@ -80,20 +84,24 @@ def Define_query_window(self): Initiate seach for information about selected option by selecting confirmation button. """ - query_text = ["Search", "Zoek"] + search_text = ["Search for ", "Zoek naar "] + if self.search_for == 'object': + self.search_name = search_text[self.GUI_lang_index] + 'object related to ' \ + + self.relator_obj.name + else: + self.search_name = search_text[self.GUI_lang_index] + self.search_for self.query_widget = gui.Widget(height='100%', width='100%', style={'display': 'block', 'background-color': '#eeffdd'}) - search_title = ['A table for searching and selecting objects ' - 'from the semantic network (dictionary)', - 'Een tabel voor het zoeken en selecteren van objecten ' - 'uit het semantische netwerk (woordenboek)'] - self.query_widget.attributes['title'] = search_title[self.GUI_lang_index] self.user_interface.views_noteb.add_tab(self.query_widget, - query_text[self.GUI_lang_index], + self.search_name, self.user_interface.tab_cb) - - self.first_line_widget = gui.HBox(height=20, width=750, margin='4px', + self.query_widget.attributes['title'] = 'Specify a (part of a) name or uid ' \ + 'and select one of the presented options' + line_width = 750 + if self.search_for == 'object': + line_width = 850 + self.first_line_widget = gui.HBox(height=20, width=line_width, margin='4px', style={'position': 'static', 'background-color': '#eeffdd'}) # Define a reply language with the language selector @@ -138,14 +146,18 @@ def Define_query_window(self): confirm = ['Confirm', 'Bevestig'] close = ['Close', 'Sluit'] confirm_button = gui.Button(confirm[self.GUI_lang_index], width=100, height=20) - confirm_button.attributes['title'] = 'Confirm that selected option is searched for' - confirm_button.onclick.connect(self.Formulate_query_spec) + if self.search_for == 'subject': + confirm_button.attributes['title'] = 'Confirm that selected option is searched for' + else: + confirm_button.attributes['title'] = 'Confirm that options for expression ' \ + 'of knowledge are selected' + confirm_button.onclick.connect(self.formulate_expression) search_close = gui.Button(close[self.GUI_lang_index], width=100, height=20) search_close.attributes['title'] = 'Close the search window' search_close.onclick.connect(self.user_interface.Close_tag, self.user_interface.views_noteb, - query_text[self.GUI_lang_index]) # self.query_widget, + self.search_name) # Widget locations in grid self.first_line_widget.append(case_sensitive_box) @@ -155,42 +167,29 @@ def Define_query_window(self): self.first_line_widget.append(self.reply_lang_label) self.first_line_widget.append(self.reply_lang_box) self.first_line_widget.append(confirm_button) + if self.search_for == 'object': + file_text = ['Search file', 'Zoek file'] + file_button = gui.Button(file_text[self.GUI_lang_index], width=100, height=20) + file_button.attributes['title'] = 'Search for document that is related to object' + file_button.onclick.connect(self.Search_file_with_document) + self.first_line_widget.append(file_button) self.first_line_widget.append(search_close) self.query_widget.append(self.first_line_widget) - # Define English and Dutch example values (initial options) for query - lhTermListEN = ['?', 'Paris', 'Eiffel tower', 'France'] - relTermListEN = ['?', 'is related to (a)', 'is related to', 'is classified as a', - 'is located in', 'has as part'] - rhTermListEN = ['?', 'city', 'tower', 'country'] - uomTermListEN = ['', 'inch', 'mi', 's', 'degC', 'psi'] - - lhTermListNL = ['?', 'N51', 'Groningen', 'Parijs', 'Eiffeltoren', 'Frankrijk'] - relTermListNL = ['?', 'is een soort', 'is gerelateerd aan (een)', 'is gerelateerd aan', - 'is geclassificeerd als een', 'bevindt zich in', 'heeft als deel'] - rhTermListNL = ['?', 'isolatieplaat', 'weg', 'dorp', 'stad', 'toren', 'land'] - uomTermListNL = ['', 'mm', 'm', 's', '°C', 'bar'] - - if self.GUI_lang_name == 'Nederlands' or 'Dutch': - lhTermListD = lhTermListNL - relTermListD = relTermListNL - rhTermListD = rhTermListNL - uomTermListD = uomTermListNL - else: - lhTermListD = lhTermListEN - relTermListD = relTermListEN - rhTermListD = rhTermListEN - uomTermListD = uomTermListEN - # Set default values in StringVar's - self.q_lh_name_str = lhTermListD[0] - self.q_rel_name_str = relTermListD[0] - self.q_rh_name_str = rhTermListD[0] - self.q_uom_name_str = uomTermListD[0] - self.q_lh_uid_str = '' - self.q_rel_uid_str = '' - self.q_rh_uid_str = '' - self.q_uom_uid_str = '' + self.q_lh_name = '' + self.q_rel_name = '' + self.q_rh_name = '' + self.q_uom_name = '' + self.q_lh_uid = '' + self.q_rel_uid = '' + self.q_rh_uid = '' + self.q_uom_uid = '' + self.query.q_lh_uid = '' + self.query.q_rel_uid = '' + self.query.q_rh_uid = '' + self.query.q_uom_uid = '' + self.query.q_uom_name = '' lhCondQStr = [] relCondQStr = [] @@ -207,60 +206,89 @@ def Define_query_window(self): # rh_term = ["Right hand term", "Rechter term"] # uom_term = ["Unit of measure", "Meeteenheid"] - # Query variables widgets definition + # Lh name label and uid label and uid widget self.third_line_widget = gui.HBox(height=20, width='100%', style='background-color:#eeffdd') self.label_frame = gui.HBox(height=20, width=300, style='background-color:#eeffdd') - lhNameLbl = gui.Label(lh_term[self.GUI_lang_index], height=20, width=160, - style='background-color:#eeffdd') - lhNameLbl.attributes['title'] = 'Specify a text string as part of the name '\ - 'of an object to be searched' - lhUIDLbl = gui.Label('UID:', height=20, width=40, - style='background-color:#eeffdd') - lhUIDLbl.attributes['title'] = 'A unique identifier of the searched object '\ - '(specified or found)' - - self.q_lh_uid_widget = gui.TextInput(self.q_lh_uid_str, height=20, width=100, + lh_name_label = gui.Label(lh_term[self.GUI_lang_index], height=20, width=160, + style='background-color:#eeffdd') + lh_name_label.attributes['title'] = 'Specify a text string as part of the name '\ + 'of an object to be searched' + lh_uid_label = gui.Label('UID:', height=20, width=40, + style='background-color:#eeffdd') + lh_uid_label.attributes['title'] = 'A unique identifier of the searched object '\ + '(specified or found)' + + self.q_lh_uid_widget = gui.TextInput(self.q_lh_uid, height=20, width=100, style={'background-color': '#ffffc0', "border-width": "1px", "border-style": "solid"}) self.q_lh_uid_widget.attributes['title'] = 'A unique identifier of the searched object '\ '(specified or found' self.q_lh_uid_widget.onkeyup.connect(self.Lh_uid_command) - self.label_frame.append(lhNameLbl) - self.label_frame.append(lhUIDLbl) + self.label_frame.append(lh_name_label) + self.label_frame.append(lh_uid_label) self.label_frame.append(self.q_lh_uid_widget) self.third_line_widget.append(self.label_frame) self.query_widget.append(self.third_line_widget) - self.fourth_line_widget = gui.HBox(height=60, width='100%', + # Lh_name (line 4) + self.fourth_line_widget = gui.HBox(height=84, width='100%', style={'background-color': '#eeffdd', 'justify-content': 'flex-start', 'align-items': 'flex-start'}) self.query_widget.append(self.fourth_line_widget) - self.name_frame = gui.VBox(height=60, width=300, + self.name_frame = gui.VBox(height=85, width=300, style={'background-color': '#eeffdd', 'justify-content': 'flex-start', 'align-items': 'flex-start'}) - self.q_lh_name_widget = gui.TextInput(height=20, width=300, + self.q_lh_name_widget = gui.TextInput(self.q_lh_name, height=20, width=300, style={'background-color': '#ffffb0', - 'border-width': '2px', + 'border-width': '1px', 'border-style': 'solid', 'justify-content': 'flex-start', 'align-items': 'flex-start'}) - self.dummy_widget = gui.Label('', height=40, width=300, - style={'background-color': '#eeffdd'}) - self.q_lh_name_widget.attributes['title'] = 'Enter a text string that is (part of) '\ 'a name of the searched object' - self.q_lh_name_widget.onkeyup.connect(self.Lh_search_cmd) + self.q_lh_name_widget.onkeyup.connect(self.lh_search_cmd) self.name_frame.append(self.q_lh_name_widget) - self.name_frame.append(self.dummy_widget) + # When knowledge is added specify kind of relation and right hand object + if self.search_for == 'object': + self.query.q_lh_uid = self.relator_obj.uid + self.query.q_lh_name = self.relator_obj.name + self.q_lh_uid_widget.set_value(self.relator_obj.uid) + self.q_lh_name_widget.set_value(self.relator_obj.name) + self.q_rel_name_widget = gui.TextInput(self.q_rel_name, height=20, width=300, + style={'background-color': '#ffffb0', + 'border-width': '1px', + 'border-style': 'solid', + 'justify-content': 'flex-start'}) + self.q_rel_name_widget.onkeyup.connect(self.rel_search_cmd) + + self.q_rh_name_widget = gui.TextInput(self.q_rh_name, height=20, width=300, + style={'background-color': '#ffffb0', + 'border-width': '1px', + 'border-style': 'solid', + 'justify-content': 'flex-start'}) + self.q_rh_name_widget.onkeyup.connect(self.rh_search_cmd) + + self.q_uom_name_widget = gui.TextInput(self.q_rh_name, height=20, width=300, + style={'background-color': '#ffffb0', + 'border-width': '1px', + 'border-style': 'solid', + 'justify-content': 'flex-start'}) + self.q_uom_name_widget.onkeyup.connect(self.uom_search_cmd) + self.name_frame.append(self.q_rel_name_widget) + self.name_frame.append(self.q_rh_name_widget) + self.name_frame.append(self.q_uom_name_widget) + else: + self.dummy_widget = gui.Label('', height=63, width=300, + style={'background-color': '#eeffdd'}) + self.name_frame.append(self.dummy_widget) self.fourth_line_widget.append(self.name_frame) # Definition display widget - # self.fifth_line_widget = gui.HBox(height=60, width='100%') def_text = ['Definition of the selected object:', 'Definitie van het geselecteerde object:'] def_label = gui.Label(def_text[self.GUI_lang_index], height=20, width='100%', @@ -268,12 +296,19 @@ def Define_query_window(self): def_label.attributes['title'] = 'First select an object below, '\ 'then its definition will appear' # fullDefQStr = '' - self.full_def_widget = gui.TextInput(single_line=False, width='100%', height=60, + self.full_def_widget = gui.TextInput(single_line=False, width='100%', height=85, style={'justify-content': 'flex-start', 'align-items': 'flex-start', 'margin-left': '5px', 'border-width': '1px', 'border-style': 'solid'}) + if self.search_for == 'object': + self.full_def_widget.attributes['title'] = \ + 'Enter the partial definitiom of the selected object, '\ + 'typically starting with "that ..."' + else: + self.full_def_widget.attributes['title'] = \ + 'Display of the definitiom of the selected object' self.third_line_widget.append(def_label) self.fourth_line_widget.append(self.full_def_widget) @@ -298,6 +333,11 @@ def Define_query_window(self): 'border-style': 'solid'}) self.options_box.style['justify-content'] = 'flex-start' self.options_box.style['align-items'] = 'flex-start' + options_title = ['A table for searching and selecting objects ' + 'from the semantic network (dictionary)', + 'Een tabel voor het zoeken en selecteren van objecten ' + 'uit het semantische netwerk (woordenboek)'] + self.options_box.attributes['title'] = options_title[self.GUI_lang_index] select_term = ["Select one of the following options:", "Kies één van de volgende opties:"] self.options_heading = gui.Label(select_term[self.GUI_lang_index], @@ -321,7 +361,7 @@ def Define_query_window(self): comm_col[self.GUI_lang_index], lang_col[self.GUI_lang_index])] self.options_table.append_from_list(self.options_table_head, fill_title=True) - self.options_table.on_table_row_click.connect(self.Set_selected_q_lh_term) + self.options_table.on_table_row_click.connect(self.process_selected_option) self.options_widget = False # Aliases define alias label and alias box @@ -392,6 +432,31 @@ def Define_query_window(self): 'The reply language is {}'.format(self.user_interface.reply_lang_name), 'De antwoordtaal is {}'.format(self.user_interface.reply_lang_name)) + def Search_file_with_document(self, widget): + """ Select one file in a dialog and relate the file to the object.""" + self.read_file_container = gui.Widget(style={'width': '220px', 'display': 'block', + 'overflow': 'auto', 'text-align': 'center'}) + self.user_interface.container.append(self.read_file_container) + # Select one or more files to be imported + self.dialog = gui.FileSelectionDialog('File selection dialog', + 'Select one file', + False, '.', + style='background-color:#eeffdd') + self.dialog.confirm_value.connect(self.on_fileselection_dialog_confirm) + self.dialog.cancel_dialog.connect(self.on_dialog_cancel) + self.dialog.show(self) + + def on_fileselection_dialog_confirm(self, widget, filelist): + ''' A list() of filenames and folders is returned''' + print('Selected file: {}'.format(filelist)) + self.file_path_names = filelist + + def on_dialog_cancel(self, widget): + self.set_root_widget(self.user_interface.container) + + def set_root_widget(self, root_widget): + self.user_interface.set_root_widget(root_widget) + def Determine_reply_language(self, widget): ''' Get the user specified reply language and report it.''' reply_lang_name = self.reply_lang_box.get() @@ -406,15 +471,11 @@ def Lh_uid_command(self, widget, new_value): == OptionsTable: option_nr, whetherKnown, langUIDres, commUIDres, result_string, resultUID, is_called_uid, kindKnown, kind """ + self.search_for = 'subject' self.lh_options[:] = [] - # Remove possible earlier options by making the options_table empty if self.options_widget is False: - self.options_box.append(self.options_heading) - self.options_box.append(self.options_table) - self.options_widget = True - self.sixth_line_left_box.append(self.options_box) - self.sixth_line_box.append(self.sixth_line_left_box) - + self.add_options_table() + # Remove possible earlier options by making the options_table empty self.options_table.empty() self.options_table.append_from_list(self.options_table_head, fill_title=True) @@ -459,6 +520,17 @@ def Lh_uid_command(self, widget, new_value): except KeyError: pass + def add_options_table(self): + """ Append heading and options_table to options_box + and append options_box to sixth_line_left_box + and that to sixth_line_box. + """ + self.options_box.append(self.options_heading) + self.options_box.append(self.options_table) + self.options_widget = True + self.sixth_line_left_box.append(self.options_box) + self.sixth_line_box.append(self.sixth_line_left_box) + def set_case(self, widget, new_value): ''' Depending on user input determine whether the search string is case sensitive''' case_sens = new_value # self.case_sensitive_var.get() @@ -470,13 +542,13 @@ def set_case(self, widget, new_value): def set_front_end(self, widget, new_value): ''' Depending on user input determine whether the front end part of the found name should comply with the front end part of the search string.''' - front_end = self.front_end_match_var.get() + front_end = new_value if front_end: self.fe = 'fi' # front end identical else: self.fe = 'pi' # part identical - def Lh_search_cmd(self, widget, new_value): + def lh_search_cmd(self, widget, new_value): """ Search or Query in semantic network An entry in QueryWindow can be just a name (lh_string) (for search on UID see Lh_uid_command) @@ -490,152 +562,242 @@ def Lh_search_cmd(self, widget, new_value): Search in vocabulary for left hand term as part of building a question. - == OptionsTable: option_nr, whetherKnown, langUIDres, commUIDres, - result_string, resultUID, is_called_uid, kindKnown,kind + == Options_table: option_nr, whetherKnown, langUIDres, commUIDres, + result_string, resultUID, is_called_uid, kindKnown, kind + """ + self.search_for = 'subject' + + self.option_search_cmd(widget, new_value) + +## self.string_commonality = self.cs + self.fe +## +## self.query.q_lh_uid = 0 +## # Delete previous items in the lh_options table +## self.lh_options[:] = [] +## # If no options_table yet, then add options_table to sixth_line_left_box +## if self.options_widget is False: +## self.add_options_table() +## # Remove possible earlier options by making the options_table empty +## self.options_table.empty() +## self.options_table.append_from_list(self.options_table_head, fill_title=True) +## +## # Determine lh_options for lh term in query +## self.search_string = new_value # self.q_lh_name_widget.get() +## self.found_lh_uid, self.lh_options = self.Solve_unknown() +## # Debug print(" Found lh: ", self.lh_string, self.unknown_quid, +## # self.lh_options[0:3]) +## +## # => lh_options: option_nr, whetherKnown, langUIDres, commUIDres, result_string, +## # resultUID, is_called_uid, kindKnown, kind +## # Sort the list of options alphabetically by name, +## # and determine lang_names and display options +## if len(self.lh_options) > 0: +## if len(self.lh_options) > 1: +## # Sort options by name +## self.lh_options.sort(key=itemgetter(4)) +## # Find lang_name and comm_name from uids for option display +## for option in self.lh_options: +## if option[2] == '': +## lang_name = 'unknown' +## else: +## if self.GUI_lang_index == 1: +## lang_name = self.gel_net.lang_dict_NL[option[2]] +## else: +## lang_name = self.gel_net.lang_dict_EN[option[2]] +## if option[3] == '': +## comm_name = 'unknown' +## else: +## comm_name = self.gel_net.community_dict[option[3]] +## +## # Display option in lh_options table +## uid = option[5] +## name = option[4] +## kind_name = option[8] +## opt = [uid, name, kind_name, comm_name, lang_name] +## +## row_widget = gui.TableRow() +## for field in opt: +## row_item = gui.TableItem(text=field, +## style={'text-align': 'left'}) +## row_widget.append(row_item, field) +## self.options_table.append(row_widget, opt[1]) +## +## # Display lh_object uid +## self.query.q_lh_uid = self.lh_options[0][5] + + # Delete earlier definition text. Then replace by new definition text + full_def = '' + self.full_def_widget.set_text(full_def) +## int_q_lh_uid, integer = Convert_numeric_to_integer(self.query.q_lh_uid) +## if integer is False or int_q_lh_uid >= 100: +## # If lh_object is known then determine and display full definition +## self.query.q_lh_category = self.lh_options[0][8] +## obj = self.gel_net.uid_dict[self.query.q_lh_uid] +## # Determine the full definition of the obj in the preferred language +## lang_name, comm_name, preferred_name, full_def = \ +## self.user_interface.Determine_name_in_context(obj) +## # Display full definition +## self.full_def_widget.set_text(full_def) + + def option_search_cmd(self, widget, new_value): + """ Search in semantic network for a string in vocabulary for candidates + (lh_string, rel_string, rh_string, uom_string) + commonality = the extent in which the found string + corresponds to the search string + (default: csfi-case sensitive, front-end identical) + Search for string in vocabulary for candidates for right hand term + and build a question + + == Options: option_nr, whetherKnown, langUIDres, commUIDres, + result_string, resultUID, is_called_uid, kindKnown, kind """ - # Tkinter options to be done: if event.keysym not in ['Shift_L', 'Shift_R']: self.string_commonality = self.cs + self.fe - self.query.q_lh_uid = 0 - self.lh_options[:] = [] # If no options_table yet, then add options_table to sixth_line_left_box if self.options_widget is False: - self.options_box.append(self.options_heading) - self.options_box.append(self.options_table) - self.options_widget = True - self.sixth_line_left_box.append(self.options_box) - self.sixth_line_box.append(self.sixth_line_left_box) + self.add_options_table() + # Remove possible earlier options by making the options_table empty self.options_table.empty() self.options_table.append_from_list(self.options_table_head, fill_title=True) - # Determine lh_options for lh term in query - self.search_string = new_value # self.q_lh_name_widget.get() - self.found_lh_uid, self.lh_options = self.Solve_unknown() - # Debug print(" Found lh: ", self.lh_string, self.unknown_quid, - # self.lh_options[0:3]) + # Determine options for term in expression + self.search_string = new_value + self.found_any_uid, self.any_options = self.Solve_unknown() - # => lh_options: option_nr, whetherKnown, langUIDres, commUIDres, result_string, - # resultUID, is_called_uid, kindKnown, kind - # Sort the list of options alphabetically by name, + # == any_options: option_nr, whetherKnown, lang_uid, comm_uid, + # result_string, result_uid, is_called_uid, kindKnown, kind + # If options are available, + # then sort the list of options, # and determine lang_names and display options - if len(self.lh_options) > 0: - if len(self.lh_options) > 1: - # Sort options by name - self.lh_options.sort(key=itemgetter(4)) - # Find lang_name and comm_name from uids for option display - for option in self.lh_options: - if option[2] == '': + if len(self.any_options) > 0: +## self.query.q_rh_uid = self.rh_options[0][5] +## self.q_rh_uid.set(str(self.query.q_rh_uid)) +## self.query.q_rh_category = self.rh_options[0][8] + if len(self.any_options) > 1: + # Sort the list of options alphabetically by name + self.any_options.sort(key=itemgetter(4)) + for option in self.any_options: + lang_uid = option[2] + comm_uid = option[3] + if lang_uid == 0: lang_name = 'unknown' else: if self.GUI_lang_index == 1: - lang_name = self.gel_net.lang_dict_NL[option[2]] + lang_name = self.gel_net.lang_dict_NL[lang_uid] else: - lang_name = self.gel_net.lang_dict_EN[option[2]] - if option[3] == '': + lang_name = self.gel_net.lang_dict_EN[lang_uid] + if comm_uid == 0: comm_name = 'unknown' else: - comm_name = self.gel_net.community_dict[option[3]] - - # Display option in lh_options table + comm_name = self.gel_net.community_dict[comm_uid] + + # Display option in options table uid = option[5] name = option[4] kind_name = option[8] opt = [uid, name, kind_name, comm_name, lang_name] - row_widget = gui.TableRow() for field in opt: row_item = gui.TableItem(text=field, style={'text-align': 'left'}) row_widget.append(row_item, field) - self.options_table.append(row_widget, opt[1]) + self.options_table.append(row_widget, opt[1]) - # Display lh_object uid - self.query.q_lh_uid = self.lh_options[0][5] +## # Display any_object uid and name +## self.query.q_rh_uid = self.any_options[0][5] +## self.query.q_rh_name = self.any_options[0][4] # Delete earlier definition text. Then replace by new definition text full_def = '' - int_q_lh_uid, integer = Convert_numeric_to_integer(self.query.q_lh_uid) - if integer is False or int_q_lh_uid >= 100: - # If lh_object is known then determine and display full definition - self.query.q_lh_category = self.lh_options[0][8] - obj = self.gel_net.uid_dict[self.query.q_lh_uid] - # Determine the full definition of the obj in the preferred language - lang_name, comm_name, preferred_name, full_def = \ - self.user_interface.Determine_name_in_context(obj) - # Display full definition self.full_def_widget.set_text(full_def) - - def Rel_search_cmd(self, widget): - """ Search or Query in Ontology and Model +## int_q_rh_uid, integer = Convert_numeric_to_integer(self.query.q_rh_uid) +## if integer is False or int_q_rh_uid >= 100: +## # If rh_object is known then determine and display full definition +## self.query.q_rh_category = self.rh_options[0][8] +## obj = self.gel_net.uid_dict[self.query.q_rh_uid] +## # Determine the full definition of the obj in the preferred language +## lang_name, comm_name, preferred_name, full_def = \ +## self.user_interface.Determine_name_in_context(obj) +## # Display full definition +## self.full_def_widget.set_text(full_def) + + def rel_search_cmd(self, widget, new_value): + """ Search or Query in semantic network Entry in QueryWindow is a question with possible condition expressions - (lh_string, rel_string, rh_string): + (lh_string, rel_string, rh_string, uom_string): - lhCommonality = 'csfi' - lhCommonality = input('Lh-commonality - (default: csfi-case sensitive, front-end identical): ') + commonality = the extent in which the found string corresponds to the search string + (default: csfi-case sensitive, front-end identical) Search in vocabulary for left hand, relation type and right hand terms - and build a question + for building an expression (question or assertion/statement) == Options: option_nr, whetherKnown, langUIDres, commUIDres, - result_string, resultUID, is_called_uid, kindKnown,kind + result_string, resultUID, is_called_uid, kindKnown, kind """ - - # Debug print('Rel Entry:',event.char) - # Tkinter options to be done: if event.keysym not in ['Shift_L', 'Shift_R']: - - # front_end = self.front_end_match_var.get() - # case_sens = self.case_sensitive_var.get() - - # Delete previous list of rel_options in tree - self.rel_options[:] = [] - x = self.rel_options_tree.get_children() - for item in x: - self.rel_options_tree.delete(item) - - # Get relation type name (rel_string) from user interface - # if event != '': rel_string = rel_string # + event.char - rel_string = self.q_rel_name - if rel_string == 'any': - if self.GUI_lang_index == 1: - rel_string = 'binaire relatie' - else: - rel_string = 'binary relation' - if rel_string == '': - rel_string = 'binary relation' - self.string_commonality = 'csfi' - self.search_string = rel_string - self.foundRel, self.rel_options = self.Solve_unknown() - # Debug print(' OptRel:',self.rel_options) - - # == rel_opions: option_nr,whetherKnown, langUIDres, commUIDres, - # result_string, resultUID, is_called_uid, kindKnown,kind - # If rel_options are available, then sort the list and display in rel_options tree - if len(self.rel_options) > 0: - self.query.q_rel_uid = self.rel_options[0][5] - int_q_rel_uid, integer = Convert_numeric_to_integer(self.query.q_rel_uid) - if integer is False or int_q_rel_uid > 100: - # obj = self.gel_net.uid_dict[self.query.q_rel_uid] - self.q_rel_uid_str.set(str(self.query.q_rel_uid)) - if len(self.rel_options) > 1: - # Sort the list of options alphabetically by name - self.rel_options.sort(key=itemgetter(4)) - for option in self.rel_options: - if option[2] == 0: - lang_name = 'unknown' - else: - lang_name = self.gel_net.lang_uid_dict[option[2]] - if option[3] == 0: - comm_name = 'unknown' - else: - comm_name = self.gel_net.community_dict[option[3]] - opt = [option[5], option[4], option[8], comm_name, lang_name] - self.rel_options_tree.insert('', index='end', values=opt) - - def Rh_search_cmd(self, widget): - """ Search or Query in Ontology and Model - An entry in QueryWindow (lh_string, rel_string, rh_string) + self.search_for = 'kind of relation' + + self.option_search_cmd(widget, new_value) + +## bin_rel_text = ['binary relation', 'binaire relatie'] +## self.string_commonality = self.cs + self.fe +## # Delete previous list of rel_options in tree +## self.rel_options[:] = [] +## # If no options_table yet, then add options_table to sixth_line_left_box +## if self.options_widget is False: +## self.add_options_table() +## # Remove possible earlier options by making the options_table empty +## self.options_table.empty() +## self.options_table.append_from_list(self.options_table_head, fill_title=True) +## +## # Determine rel_options for rel term in query +## self.search_string = new_value # self.q_rel_name_widget.get() +## self.found_rel_uid, self.rel_options = self.Solve_unknown() +## +#### x = self.rel_options_tree.get_children() +#### for item in x: +#### self.rel_options_tree.delete(item) +#### +#### # Get relation type name (rel_string) from user interface +#### # if event != '': rel_string = rel_string # + event.char +#### rel_string = self.q_rel_name +#### if rel_string == 'any': +#### rel_string = bin_rel_text[self.GUI_lang_index] +#### elif rel_string == '': +#### rel_string = bin_rel_text[1] +#### self.string_commonality = 'csfi' +#### self.search_string = rel_string +#### self.foundRel, self.rel_options = self.Solve_unknown() +## # Debug print(' OptRel:',self.rel_options) +## +## # == rel_opions: option_nr,whetherKnown, langUIDres, commUIDres, +## # result_string, resultUID, is_called_uid, kindKnown,kind +## # If rel_options are available, then sort the list and display in rel_options tree +## if len(self.rel_options) > 0: +## self.query.q_rel_uid = self.rel_options[0][5] +## int_q_rel_uid, integer = Convert_numeric_to_integer(self.query.q_rel_uid) +## if integer is False or int_q_rel_uid > 100: +## # obj = self.gel_net.uid_dict[self.query.q_rel_uid] +## self.q_rel_uid.set(str(self.query.q_rel_uid)) +## if len(self.rel_options) > 1: +## # Sort the list of options alphabetically by name +## self.rel_options.sort(key=itemgetter(4)) +## for option in self.rel_options: +## if option[2] == 0: +## lang_name = 'unknown' +## else: +## lang_name = self.gel_net.lang_uid_dict[option[2]] +## if option[3] == 0: +## comm_name = 'unknown' +## else: +## comm_name = self.gel_net.community_dict[option[3]] +## opt = [option[5], option[4], option[8], comm_name, lang_name] +## self.rel_options_tree.insert('', index='end', values=opt) + + def rh_search_cmd(self, widget, new_value): + """ Search or Query in semantic network + An entry in QueryWindow (lh_string, rel_string, rh_string, uom) is a question with possible condition expressions: rhCommonality = input('Rh-commonality (default: csfi-case sensitive, front-end identical): ') @@ -643,46 +805,87 @@ def Rh_search_cmd(self, widget): and build a question == Options: option_nr, whetherKnown, langUIDres, commUIDres, - result_string, resultUID, is_called_uid, kindKnown,kind + result_string, resultUID, is_called_uid, kindKnown, kind """ - # Debug print('Rh Entry:',event.char) - # Tkinter options to be done: if event.keysym not in ['Shift_L', 'Shift_R']: - - # Delete previous items in the rh_options in tree - self.rh_options[:] = [] - x = self.rh_options_tree.get_children() - for item in x: - self.rh_options_tree.delete(item) - - # Get the rh_string and search for options in the dictionary - rh_string = self.q_rh_name_widget.get() - self.search_string = rh_string - self.foundRh, self.rh_options = self.Solve_unknown() - # Debug print(' OptRh:',self.rh_options); - - # == rh_options: option_nr, whetherKnown, langUIDres, commUIDres, - # result_string, resultUID, is_called_uid, kindKnown,kind - # If rh_options are available, - # then sort the list and display them in the rh_options tree - if len(self.rh_options) > 0: - self.query.q_rh_uid = self.rh_options[0][5] - # obj = self.gel_net.uid_dict[self.query.q_rh_uid] - self.q_rh_uid_str.set(str(self.query.q_rh_uid)) - self.query.q_rh_category = self.rh_options[0][8] - if len(self.rh_options) > 1: - # Sort the list of options alphabetically by name - self.rh_options.sort(key=itemgetter(4)) - for option in self.rh_options: - if option[2] == 0: - lang_name = 'unknown' - else: - lang_name = self.gel_net.lang_uid_dict[option[2]] - if option[3] == 0: - comm_name = 'unknown' - else: - comm_name = self.gel_net.community_dict[option[3]] - opt = [option[5], option[4], option[8], comm_name, lang_name] - self.rh_options_tree.insert('', index='end', values=opt) + self.search_for = 'object' + +## # Delete previous items in the rh_options in options_table widget +## self.query.q_rh_uid = 0 +## self.rh_options[:] = [] + + self.option_search_cmd(widget, new_value) + +## self.string_commonality = self.cs + self.fe +## # If no options_table yet, then add options_table to sixth_line_left_box +## if self.options_widget is False: +## self.add_options_table() +## # Remove possible earlier options by making the options_table empty +## self.options_table.empty() +## self.options_table.append_from_list(self.options_table_head, fill_title=True) +## +## # Determine rh_options for rh term in query +## self.search_string = new_value +## self.found_rh_uid, self.rh_options = self.Solve_unknown() +## +## # == rh_options: option_nr, whetherKnown, langUIDres, commUIDres, +## # result_string, resultUID, is_called_uid, kindKnown, kind +## # If rh_options are available, +## # then sort the list of options, +## # and determine lang_names and display options +## if len(self.rh_options) > 0: +#### self.query.q_rh_uid = self.rh_options[0][5] +#### self.q_rh_uid.set(str(self.query.q_rh_uid)) +#### self.query.q_rh_category = self.rh_options[0][8] +## if len(self.rh_options) > 1: +## # Sort the list of options alphabetically by name +## self.rh_options.sort(key=itemgetter(4)) +## for option in self.rh_options: +## if option[2] == 0: +## lang_name = 'unknown' +## else: +## if self.GUI_lang_index == 1: +## lang_name = self.gel_net.lang_dict_NL[option[2]] +## else: +## lang_name = self.gel_net.lang_dict_EN[option[2]] +## if option[3] == 0: +## comm_name = 'unknown' +## else: +## comm_name = self.gel_net.community_dict[option[3]] +## +## # Display option in rh_options table +## uid = option[5] +## name = option[4] +## kind_name = option[8] +## opt = [uid, name, kind_name, comm_name, lang_name] +## row_widget = gui.TableRow() +## for field in opt: +## row_item = gui.TableItem(text=field, +## style={'text-align': 'left'}) +## row_widget.append(row_item, field) +## self.options_table.append(row_widget, opt[1]) +## +## # Display rh_object uid +## self.query.q_rh_uid = self.rh_options[0][5] +## self.query.q_rh_name = self.rh_options[0][4] +## +## # Delete earlier definition text. Then replace by new definition text +## full_def = '' +## int_q_rh_uid, integer = Convert_numeric_to_integer(self.query.q_rh_uid) +## if integer is False or int_q_rh_uid >= 100: +## # If rh_object is known then determine and display full definition +## self.query.q_rh_category = self.rh_options[0][8] +## obj = self.gel_net.uid_dict[self.query.q_rh_uid] +## # Determine the full definition of the obj in the preferred language +## lang_name, comm_name, preferred_name, full_def = \ +## self.user_interface.Determine_name_in_context(obj) +## # Display full definition +## self.full_def_widget.set_text(full_def) + + def uom_search_cmd(self, widget, new_value): + """ Search in semantic network for the unit of measure (uom).""" + self.search_for = 'uom' + + self.option_search_cmd(widget, new_value) def Determine_selected_aspects(self, widget, row, item): ''' Determine one or more selected aspects and their values @@ -702,8 +905,8 @@ def Determine_selected_aspects(self, widget, row, item): def Solve_unknown(self): """ Determine the available options (UIDs and names) in the dictionary that match the search_string. - Collect options in lh, rel and rh optionsTables for display and selection. - - search_string = the string to be found in Gel_dict + Collect options in lh, rel, rh and uom optionsTables for display and selection. + - search_string = the string to be found in gel_dict with corresponding lang_uid and comm_uid. - self.string_commonality is one of: cipi, cspi, cii, csi, cifi, csfi @@ -839,12 +1042,28 @@ def Solve_unknown(self): # (being the unknown) and next UID. else: if self.search_string not in self.names_of_unknowns: + self.unknown_quid += 1 self.user_interface.message_ui( - 'String "{}" is not found in the dictionary. UID = {}. '. + 'String "{}" is not found in the dictionary. New UID = {}. '. format(self.search_string, self.unknown_quid), - 'Term "{}" is niet gevonden in het woordenboek. UID = {}. '. + 'Term "{}" is niet gevonden in het woordenboek. Nieuw UID = {}. '. format(self.search_string, self.unknown_quid)) found_uid = self.unknown_quid + self.names_of_unknowns.append(self.search_string) + # Create an option for a new object + unknown = Anything(str(self.unknown_quid), result_string) + self.unknowns.append(unknown) + option_nr = 1 + option.append(option_nr) + option.append(whetherKnown) + option.append(self.GUI_lang_pref_uids[1]) + option.append(self.comm_pref_uids[0]) + option.append(self.search_string) + option.append(str(self.unknown_quid)) + option.append(is_called_uid) + option.append(objectTypeKnown) + option.append(self.unknown_kind[self.GUI_lang_index]) + options.append(option) else: # Search in unknowns for object with name search_string for obj in self.unknowns: @@ -857,9 +1076,9 @@ def Solve_unknown(self): 'De gevonden UID is blanco, hetgeen niet correct is.') return found_uid, options - def Set_selected_q_lh_term(self, window, row, item): - """ Put the lh_object that is selected from lh_options - in the query (q_lh_name_str and q_lh_uid_str) + def process_selected_option(self, window, row, item): + """ Put the object that is selected from any_options + in the query (q_lh_name and q_lh_uid, q_rel, q_rh and q_uom) and display its textual definition, name and uid. Then determine the kinds of relations that relate to that lh_object or its subtypes @@ -867,45 +1086,70 @@ def Set_selected_q_lh_term(self, window, row, item): And determine the synonyms and translations of lh_object name. """ blank = '' - # Determine UID and Name of selected option + # Determine UID and Name of the selected option values = list(row.children.values()) - self.query.q_lh_uid = values[0].get_text() - # Debug print('LH_uid', self.query.q_lh_uid) + any_uid = values[0].get_text() +## self.query.q_lh_uid = values[0].get_text() + selected_name = values[1].get_text() - self.full_def_widget.set_text('') + # Delete earlier definition text in query view. full_def = '' + self.full_def_widget.set_text(full_def) + # Determine the selected object via its uid - int_q_lh_uid, integer = Convert_numeric_to_integer(self.query.q_lh_uid) + int_any_uid, integer = Convert_numeric_to_integer(any_uid) # If object is unknown then display message - if integer is True and int_q_lh_uid < 100: - search_string = values[1].get_text() + if integer is True and int_any_uid < 100: self.user_interface.message_ui( - 'Selected object with name "{}" is unknown'.format(search_string), - 'Geselecteerd object met naam "{}" is onbekend'.format(search_string)) + 'Selected object with name "{}" is unknown'.format(selected_name), + 'Geselecteerd object met naam "{}" is onbekend'.format(selected_name)) return - # Find object - obj = self.gel_net.uid_dict[self.query.q_lh_uid] + # object is known: Find object + any_object = self.gel_net.uid_dict[any_uid] + any_object.name = selected_name + # Determine the full definition and preferred_name # of the selected object in the preferred language lang_name, comm_name, preferred_name, full_def = \ - self.user_interface.Determine_name_in_context(obj) - # Debug print('FullDef:',self.query.q_lh_uid, self.query.q_lh_name, - # self.query.q_lh_category,full_def) + self.user_interface.Determine_name_in_context(any_object) # Display full definition self.full_def_widget.set_text(full_def) # Display selected UID and Name in selection fields - self.q_lh_uid_widget.set_text(self.query.q_lh_uid) - selected_name = preferred_name - self.q_lh_name_widget.set_text(selected_name) - - self.q_aspects[:] = [] - # If the lh_object is known, - # then determine the kinds of relations that relate to that lh_object - if integer is False or int_q_lh_uid >= 100: + self.q_lh_uid_widget.set_text(any_uid) + # selected_name = preferred_name + if self.search_for == 'subject': + self.q_lh_name_widget.set_text(selected_name) + self.query.q_lh_obj = any_object + self.query.q_lh_uid = any_uid + self.query.q_lh_name = selected_name + self.query.q_lh_category = any_object.category + elif self.search_for == 'kind of relation': + self.q_rel_name_widget.set_text(selected_name) + self.query.q_rel_uid = any_uid + self.query.q_rel_name = selected_name + self.query.q_rel_category = any_object.category + elif self.search_for == 'object': + self.q_rh_name_widget.set_text(selected_name) + self.query.q_rh_uid = any_uid + self.query.q_rh_name = selected_name + self.query.q_rh_category = any_object.category + elif self.search_for == 'uom': + self.q_uom_name_widget.set_text(selected_name) + self.query.q_uom_uid = any_uid + self.query.q_uom_name = selected_name + self.query.q_uom_category = any_object.category + + if self.search_for == 'subject': + lh_object = any_object + # Determine possible aspects of found lh_object + self.q_aspects[:] = [] + + # Determine the kinds of relations that relate to that lh_object + # if integer is False or int_q_lh_uid >= 100: rel_options = [] - lh_object = self.gel_net.uid_dict[self.query.q_lh_uid] + # lh_object = self.gel_net.uid_dict[self.query.q_lh_uid] # Determine list of subtypes of the lh_object sub_types, sub_type_uids = self.gel_net.Determine_subtypes(lh_object) sub_types.append(lh_object) @@ -980,37 +1224,38 @@ def Set_selected_q_lh_term(self, window, row, item): rel_options.sort() self.gel_net.rel_terms = rel_options - # If alias_box not yet filled, the fill it - if self.aliases_widget is False: - self.alias_box.append(self.alias_label) - self.alias_box.append(self.aliases_table_widget) - self.aliases_widget = True - self.sixth_line_left_box.append(self.alias_box) - # Delete previous aliases in aliases_table and add title row - self.aliases_table_widget.empty() - self.aliases_table_widget.append_from_list(self.aliases_table_head, fill_title=True) - - # Determine synonyms and translations of lh_object name in various languages - languages, alias_table = self.Determine_aliases(lh_object) - for language in languages: - # Add language_row to table - language_row = gui.TableRow() - language_item = gui.TableItem(text=language, - style={'text-align': 'left'}) - language_row.append(language_item, language_item) - self.aliases_table_widget.append(language_row, language) - - # Add aliases rowa per language to the table - for alias_row in alias_table: - if alias_row[0] == language: - row_widget = gui.TableRow() - row_item = gui.TableItem(text='') - row_widget.append(row_item, language) - for field in alias_row[1:]: - row_item = gui.TableItem(text=field, - style={'text-align': 'left'}) - row_widget.append(row_item, field) - self.aliases_table_widget.append(row_widget, alias_row[1]) + # For any_object: + # If alias_box not yet filled, the fill it + if self.aliases_widget is False: + self.alias_box.append(self.alias_label) + self.alias_box.append(self.aliases_table_widget) + self.aliases_widget = True + self.sixth_line_left_box.append(self.alias_box) + # Delete previous aliases in aliases_table and add title row + self.aliases_table_widget.empty() + self.aliases_table_widget.append_from_list(self.aliases_table_head, fill_title=True) + + # Determine synonyms and translations of lh_object name in various languages + languages, alias_table = self.Determine_aliases(any_object) + for language in languages: + # Add language_row to table + language_row = gui.TableRow() + language_item = gui.TableItem(text=language, + style={'text-align': 'left'}) + language_row.append(language_item, language_item) + self.aliases_table_widget.append(language_row, language) + + # Add aliases rowa per language to the table + for alias_row in alias_table: + if alias_row[0] == language: + row_widget = gui.TableRow() + row_item = gui.TableItem(text='') + row_widget.append(row_item, language) + for field in alias_row[1:]: + row_item = gui.TableItem(text=field, + style={'text-align': 'left'}) + row_widget.append(row_item, field) + self.aliases_table_widget.append(row_widget, alias_row[1]) def Determine_aspect_and_value_options(self, lh_obj_sub): ''' Determine in a search the characteristics of lh_object and its subtypes @@ -1116,7 +1361,7 @@ def Determine_aliases(self, obj): def Set_selected_q_rel_term(self, ind): """ Put the selected relObject name and uid from relOptions - in query (self.q_rel_name_str and self.q_rel_uid_str). + in query (self.q_rel_name and self.q_rel_uid). Then determine the rh_objects that are related to the lh_object by such a relation or its subtypes """ @@ -1126,8 +1371,8 @@ def Set_selected_q_rel_term(self, ind): # Determine UID and Name of selected option self.query.q_rel_uid = self.query.relSel[5] self.query.q_rel_name = self.query.relSel[4] - self.q_rel_uid_str.set(str(self.query.q_rel_uid)) - self.q_rel_name_str.set(self.query.q_rel_name) + self.q_rel_uid.set(str(self.query.q_rel_uid)) + self.q_rel_name.set(self.query.q_rel_name) if self.query.q_rel_name in self.gel_net.total_base_phrases: self.query.q_phrase_type_uid = '6066' @@ -1169,7 +1414,9 @@ def Set_selected_q_rel_term(self, ind): self.q_rh_name_widget.config(values=self.gel_net.rh_terms) def Set_selected_q_rh_term(self, ind): - """Put the selection of rhObject in self.q_rh_name_str and self.q_rh_uid_str""" + """ Put the selection of rhObject + in self.q_rh_name and self.q_rh_uid. + """ item = self.rh_options_tree.selection() ind = self.rh_options_tree.index(item) @@ -1177,12 +1424,17 @@ def Set_selected_q_rh_term(self, ind): # Determine UID and Name of selected option self.query.q_rh_uid = self.query.rhSel[5] self.query.q_rh_name = self.query.rhSel[4] - self.q_rh_uid_str.set(str(self.query.q_rh_uid)) - self.q_rh_name_str.set(self.query.q_rh_name) - - def Formulate_query_spec(self, widget): - """Formulte a query_spec on the network for the relation type and its subtypes. - Store resulting query expressions in candids table with the same table definition. + self.q_rh_uid.set(str(self.query.q_rh_uid)) + self.q_rh_name.set(self.query.q_rh_name) + + def formulate_expression(self, widget): + """ Formulte one or more expressions + being a query_spec on the network, based on the selected option(s) + or new knowledge. + If a kind of relation is specified + then it includes a search for it and for its subtypes. + Store resulting expressions in candids table + with the same table definition. """ # Make query_spec empty self.query.query_spec[:] = [] @@ -1190,8 +1442,7 @@ def Formulate_query_spec(self, widget): # LH: Get selected option (textString) # from the presented list of options (lh_options_tree) in QueryWindow - lh_uid_init = self.q_lh_uid_widget.get_text() - if lh_uid_init == '': + if self.query.q_lh_uid == '': self.user_interface.message_ui( 'Left hand option is not yet selected. Please try again.', 'Linker optie is nog niet geselecteerd. Probeer nogmaals.') @@ -1199,128 +1450,115 @@ def Formulate_query_spec(self, widget): # Determine UID and Name of selected lh option # and formulate query expression (query_expr) - self.query.q_lh_uid = lh_uid_init - self.query.q_lh_name = self.q_lh_name_widget.get_text() self.query.query_expr = [self.query.q_lh_uid, self.query.q_lh_name] - # Delete earlier definition text in query view. - self.full_def_widget.set_text('') - - # If lh_object is known then determine and display its full definition int_q_lh_uid, integer = Convert_numeric_to_integer(self.query.q_lh_uid) - if integer is False or int_q_lh_uid >= 100: - self.query.q_lh_obj = self.gel_net.uid_dict[self.query.q_lh_uid] - self.query.q_lh_category = self.lh_options[0][8] - - # Determine the full definition of the selected object in the preferred language - lang_name, comm_name, preferred_name, full_def = \ - self.user_interface.Determine_name_in_context(self.query.q_lh_obj) - # Debug print('Full def:', self.query.q_lh_uid, self.lh_string, - # self.query.q_lh_category, full_def) - # Display full definition - self.full_def_widget.set_text(full_def) - # Rel: Selected relation type option - # Verify whether kind of relation is specified or only lh option is selected. - # If yes then formulate query, else determine rel and rh part of query expression - - # Initial rel_uid_init set to blank ('') to indicate the no query expression is specified - # (no extended search specification) - rel_uid_init = '' - if rel_uid_init != '': - # There is a kind of relation specified. Identify its uid and name - item = self.rel_options_tree.selection() - ind = self.rel_options_tree.index(item) - print('rel_ind', ind, self.rel_options) - self.query.relSel = self.rel_options[ind] - - self.query.q_rel_uid = self.query.relSel[5] - self.query.q_rel_name = self.query.relSel[4] - self.q_rel_uid_str.set(str(self.query.q_rel_uid)) - self.q_rel_name_str.set(self.query.q_rel_name) - - int_q_rel_uid, integer = Convert_numeric_to_integer(self.query.q_rel_uid) - if integer is False or int_q_rel_uid >= 100: - self.query.q_rel_obj = self.gel_net.uid_dict[self.query.q_rel_uid] - - # Determine phraseTypeUID of self.query.q_rel_name - self.query.q_phrase_type_uid = 0 - if self.query.q_rel_name in self.gel_net.total_base_phrases: - self.query.q_phrase_type_uid = '6066' # base phrase - else: - self.query.q_phrase_type_uid = '1986' # inverse phrase - - # Determine role_players_types because of q_rel_type - self.query.rolePlayersQTypes = self.query.q_rel_obj.role_players_types - self.query.rolePlayerQTypeLH = self.query.q_rel_obj.role_player_type_lh - self.query.rolePlayerQTypeRH = self.query.q_rel_obj.role_player_type_rh - # 6068 = binary relation between an individual thing and any (kind or individual) - if self.query.rolePlayersQTypes == 'individualsOrMixed': # is related to (a) - if self.query.q_rel_name in self.gel_net.total_base_phrases: - self.query.rolePlayersQTypes = 'individualAndMixed' - self.query.rolePlayerQTypeLH = 'individual' - self.query.rolePlayerQTypeRH = 'mixed' - else: - self.query.rolePlayersQTypes = 'mixedAndIndividual' - self.query.rolePlayerQTypeLH = 'mixed' - self.query.rolePlayerQTypeRH = 'individual' - # Binary relation between an individual thing and a kind - elif self.query.rolePlayersQTypes == 'mixed': - if self.query.q_rel_name in self.gel_net.total_base_phrases: - self.query.rolePlayersQTypes = 'individualAndKind' - self.query.rolePlayerQTypeLH = 'individual' - self.query.rolePlayerQTypeRH = 'kind' - else: - self.query.rolePlayersQTypes = 'kindAndIndividual' - self.query.rolePlayerQTypeLH = 'kind' - self.query.rolePlayerQTypeRH = 'individual' - # 7071 = binary relation between a kind and any (kind or individual) - elif self.query.rolePlayersQTypes == 'kindsOrMixed': # can be related to (a) - if self.query.q_rel_name in self.gel_net.total_base_phrases: - self.query.rolePlayersQTypes = 'kindsAndMixed' # can be related to (a) - self.query.rolePlayerQTypeLH = 'kind' - self.query.rolePlayerQTypeRH = 'mixed' - else: - self.query.rolePlayersQTypes = 'mixedAndKind' # is or can be related to a - self.query.rolePlayerQTypeLH = 'mixed' - self.query.rolePlayerQTypeRH = 'kind' - else: - pass + if self.search_for in ['object', 'kind of relation', 'uom']: + # Search for related object + self.views.create_knowledge_expression() + return - # RH: Selected right hand option - # Verify whether a rh name is specified - rh_uid_init = self.q_rh_uid_widget.get() - if rh_uid_init == '': - self.user_interface.message_ui( - 'Right hand option ís not (yet) selected.', - 'Rechter optie is nog niet geselecteerd.') - else: - # There is a rh name specified. Determine its name and uid and identity - item = self.rh_options_tree.selection() - ind = self.rh_options_tree.index(item) - self.query.rhSel = self.rh_options[ind] - - self.query.q_rh_uid = self.query.rhSel[5] - self.query.q_rh_name = self.query.rhSel[4] - self.q_rh_uid_str.set(str(self.query.q_rh_uid)) - self.q_rh_name_str.set(self.query.q_rh_name) - - int_q_rh_uid, integer = Convert_numeric_to_integer(self.query.q_rh_uid) - if integer is False or int_q_rh_uid >= 100: - self.query.q_rh_obj = self.gel_net.uid_dict[self.query.q_rh_uid] - - # Report final query - queryText = ['Query ', 'Vraag '] - self.views.log_messages.insert( - 'end', '\n\n{}: {} ({}) {} ({}) {} ({})'. - format(queryText[self.GUI_lang_index], - self.query.q_lh_name, self.query.q_lh_uid, - self.query.q_rel_name, self.query.q_rel_uid, - self.query.q_rh_name, self.query.q_rh_uid)) - self.query.query_expr = [self.query.q_lh_uid, self.query.q_lh_name, - self.query.q_rel_uid, self.query.q_rel_name, - self.query.q_rh_uid, self.query.q_rh_name, - self.query.q_phrase_type_uid] +## # Deleted region for specification of a query as an expression of [lh, rel_type, rh] +## # (no extended search specification) +## # Rel: Selected relation type option +## # Verify whether kind of relation is specified or only lh option is selected. +## # If yes then formulate query, else determine rel and rh part of query expression +## +## if rel_uid_init != '': +## # There is a kind of relation specified. Identify its uid and name +## item = self.rel_options_tree.selection() +## ind = self.rel_options_tree.index(item) +## print('rel_ind', ind, self.rel_options) +## self.query.relSel = self.rel_options[ind] +## +## self.query.q_rel_uid = self.query.relSel[5] +## self.query.q_rel_name = self.query.relSel[4] +## self.q_rel_uid.set(str(self.query.q_rel_uid)) +## self.q_rel_name.set(self.query.q_rel_name) +## +## int_q_rel_uid, integer = Convert_numeric_to_integer(self.query.q_rel_uid) +## if integer is False or int_q_rel_uid >= 100: +## self.query.q_rel_obj = self.gel_net.uid_dict[self.query.q_rel_uid] +## +## # Determine phraseTypeUID of self.query.q_rel_name +## self.query.q_phrase_type_uid = 0 +## if self.query.q_rel_name in self.gel_net.total_base_phrases: +## self.query.q_phrase_type_uid = '6066' # base phrase +## else: +## self.query.q_phrase_type_uid = '1986' # inverse phrase +## +## # Determine role_players_types because of q_rel_type +## self.query.rolePlayersQTypes = self.query.q_rel_obj.role_players_types +## self.query.rolePlayerQTypeLH = self.query.q_rel_obj.role_player_type_lh +## self.query.rolePlayerQTypeRH = self.query.q_rel_obj.role_player_type_rh +## # 6068 = binary relation between an individual thing and any (kind or individual) +## if self.query.rolePlayersQTypes == 'individualsOrMixed': # is related to (a) +## if self.query.q_rel_name in self.gel_net.total_base_phrases: +## self.query.rolePlayersQTypes = 'individualAndMixed' +## self.query.rolePlayerQTypeLH = 'individual' +## self.query.rolePlayerQTypeRH = 'mixed' +## else: +## self.query.rolePlayersQTypes = 'mixedAndIndividual' +## self.query.rolePlayerQTypeLH = 'mixed' +## self.query.rolePlayerQTypeRH = 'individual' +## # Binary relation between an individual thing and a kind +## elif self.query.rolePlayersQTypes == 'mixed': +## if self.query.q_rel_name in self.gel_net.total_base_phrases: +## self.query.rolePlayersQTypes = 'individualAndKind' +## self.query.rolePlayerQTypeLH = 'individual' +## self.query.rolePlayerQTypeRH = 'kind' +## else: +## self.query.rolePlayersQTypes = 'kindAndIndividual' +## self.query.rolePlayerQTypeLH = 'kind' +## self.query.rolePlayerQTypeRH = 'individual' +## # 7071 = binary relation between a kind and any (kind or individual) +## elif self.query.rolePlayersQTypes == 'kindsOrMixed': # can be related to (a) +## if self.query.q_rel_name in self.gel_net.total_base_phrases: +## self.query.rolePlayersQTypes = 'kindsAndMixed' # can be related to (a) +## self.query.rolePlayerQTypeLH = 'kind' +## self.query.rolePlayerQTypeRH = 'mixed' +## else: +## self.query.rolePlayersQTypes = 'mixedAndKind' # is or can be related to a +## self.query.rolePlayerQTypeLH = 'mixed' +## self.query.rolePlayerQTypeRH = 'kind' +## else: +## pass +## +## # RH: Selected right hand option +## # Verify whether a rh name is specified +## rh_uid_init = self.q_rh_uid_widget.get() +## if rh_uid_init == '': +## self.user_interface.message_ui( +## 'Right hand option ís not (yet) selected.', +## 'Rechter optie is nog niet geselecteerd.') +## else: +## # There is a rh name specified. Determine its name and uid and identity +## item = self.rh_options_tree.selection() +## ind = self.rh_options_tree.index(item) +## self.query.rhSel = self.rh_options[ind] +## +## self.query.q_rh_uid = self.query.rhSel[5] +## self.query.q_rh_name = self.query.rhSel[4] +## self.q_rh_uid.set(str(self.query.q_rh_uid)) +## self.q_rh_name.set(self.query.q_rh_name) +## +## int_q_rh_uid, integer = Convert_numeric_to_integer(self.query.q_rh_uid) +## if integer is False or int_q_rh_uid >= 100: +## self.query.q_rh_obj = self.gel_net.uid_dict[self.query.q_rh_uid] +## +## # Report final query +## queryText = ['Query ', 'Vraag '] +## self.views.log_messages.insert( +## 'end', '\n\n{}: {} ({}) {} ({}) {} ({})'. +## format(queryText[self.GUI_lang_index], +## self.query.q_lh_name, self.query.q_lh_uid, +## self.query.q_rel_name, self.query.q_rel_uid, +## self.query.q_rh_name, self.query.q_rh_uid)) +## self.query.query_expr = [self.query.q_lh_uid, self.query.q_lh_name, +## self.query.q_rel_uid, self.query.q_rel_name, +## self.query.q_rh_uid, self.query.q_rh_name, +## self.query.q_phrase_type_uid] # Append query expression as first line in query_spec # query_expr = lh_uid, lh_name, rel_uid, rel_name, rh_uid_rh_name, phrase_type_uid diff --git a/Web-Communicator/Singular_to_plural.py b/Web-Communicator/Singular_to_plural.py index b1bc1bc..5b828a6 100644 --- a/Web-Communicator/Singular_to_plural.py +++ b/Web-Communicator/Singular_to_plural.py @@ -31,13 +31,19 @@ def convert_singular_to_plural(self, obj): if obj.uid not in exception_uids and obj.category not in collections \ and not (len(parts) > 1 and parts[0] == 'coll') \ and obj.category not in individuals: + singular_name = obj.name + print('Name: {} ({})'.format(singular_name, obj.uid)) # Determine the uid of the plural thing by concatination with 'coll:' # and create the object with a preliminar name - uid_plural = 'coll:' + obj.uid - singular_name = obj.name plurality_name = singular_name + 's' - self.coll = Anything(uid_plural, plurality_name) - self.coll.category = 'collection' + uid_plural = 'coll:' + obj.uid + if uid_plural not in self.gel_net.uid_dict: + self.coll = Anything(uid_plural, plurality_name) + self.coll.category = 'collection' + new_obj = True + else: + self.coll = self.gel_net.uid_dict[uid_plural] + new_obj = False # Find the name for the plural thing for every English name in context if len(obj.names_in_contexts) > 0: @@ -52,14 +58,12 @@ def convert_singular_to_plural(self, obj): elif name_in_context[0] == '910037': self.determine_dutch_plural(name_in_context) - # Debug print('Plurals:', plural.uid, plural.name, len(plural.names_in_contexts)) for name_in_context in self.coll.names_in_contexts: - # Debug print('Plural:', plural.name, plural.uid, name_in_context) - print('UID and Name of plurality:', self.coll.uid, name_in_context[2]) + print('Plurality: {} ({})'.format(name_in_context[2], self.coll.uid)) - self.add_rel_between_single_and_collection(obj, self.coll) - for relation in obj.relations: - print('Expression:', obj.name, relation) + if new_obj is True: + self.add_rel_between_single_and_collection(obj, self.coll) + return self.coll def determine_english_plural(self, name_in_context): ''' Tranform the English names_in_contexts of a kind @@ -490,18 +494,21 @@ def add_rel_between_single_and_collection(self, particular, plurality): '44': 'wc'} lang = input("Enter language 'en' or 'nl': ") + GUI_lang_index = 0 + net_name = 'Net' + gel_net = Semantic_Network(GUI_lang_index, net_name) if lang == 'nl': names = test_names_nl language_uid = language_uid_nl + gel_net.lang_uid_dict[language_uid] = language_uid_nl else: names = test_names language_uid = language_uid_en - GUI_lang_index = 0 - net_name = 'Net' - gel_net = Semantic_Network(GUI_lang_index, net_name) + gel_net.lang_uid_dict[language_uid] = language_uid_en rel_kind_uid = '4843' rel_type = Anything(rel_kind_uid, 'is classifier of each element of') gel_net.uid_dict[rel_kind_uid] = rel_type + gel_net.community_dict[community_uid] = 'Gellish' path_and_name = '' current_file = Gellish_file(path_and_name, gel_net) plurality = Plurality(gel_net, current_file) @@ -512,13 +519,17 @@ def add_rel_between_single_and_collection(self, particular, plurality): # name = input("Enter name or 'end': ") # uid = name # Only in case of manual input obj = Anything(uid, name) + descr = 'is a ...' + name_in_context = [language_uid, community_uid, name, naming_relation_uid, descr] + obj.add_name_in_context(name_in_context) if uid == '48': obj.category = 'individual' elif uid == '49': obj.category = 'kind of relation' - descr = 'something' - name_in_context = [language_uid, community_uid, name, naming_relation_uid, descr] - obj.add_name_in_context(name_in_context) - print('UID and Name of singular:', obj.uid, obj.name) # obj.names_in_contexts) - - plurality.convert_singular_to_plural(obj) + + new_obj = plurality.convert_singular_to_plural(obj) + for relation in obj.relations: + print('Single Expression:', obj.name, relation) + for new_relation in new_obj.relations: + print('Plural Expression:', new_obj.name, new_relation) + print('Single/Plural:', name_in_context, new_obj.names_in_contexts) diff --git a/Web-Communicator/User_interface.py b/Web-Communicator/User_interface.py index 1ff86cc..fdec394 100644 --- a/Web-Communicator/User_interface.py +++ b/Web-Communicator/User_interface.py @@ -35,11 +35,33 @@ def _fix_tab_widths(self): for a, li, holder in self._tabs.values(): li.style['float'] = "left" # Specify the size percentage - li.style['width'] = "%.0f%%" % (tab_w - 1) + li.style['width'] = "{}%".format(tab_w) # "%.0f%%" % (tab_w - 1) # Specify the text height - a.style['height'] = "20px" - a.style['line-height'] = "10px" + a.style['height'] = "43px" + a.style['line-height'] = "13px" + a.style['color'] = "black" + a.style['background-color'] = "#ddffdd" + a.style['border-width'] = '1px' + a.style['border-style'] = 'solid' + a.style['margin'] = '1px' + a.style['padding'] = '2px' + + def _on_tab_pressed(self, _a, _li, _holder): + # remove active on all tabs, and hide their contents + for a, li, holder in self._tabs.values(): + a.remove_class('active') + holder.style['display'] = 'none' + a.style['background-color'] = "#ddffdd" + + _a.add_class('active') + _holder.style['display'] = 'block' + _a.style['background-color'] = "#ffffdd" + + # call other callbacks + cb = self._tab_cbs[_holder.identifier] + if cb is not None: + cb() class Communicator(App): @@ -73,6 +95,7 @@ def __init__(self, *args): self.comm_pref_uids = ['492014', 'any'] # Default: 492014 = 'Gellish' self.file_path_names = [] self.q_view = None + self.search_name = ['Search for subject', 'Zoek naar subject'] super(Communicator, self).__init__(*args) @@ -324,7 +347,7 @@ def combine_files_with_network(self): ''' Select one or more Gellish files in a dialog and import the files, after syntactic verification. - The merge the file content in the semantic network. + Then merge the file content in the semantic network. ''' self.read_file_container = gui.Widget(style={'width': '220px', 'display': 'block', 'overflow': 'auto', 'text-align': 'center'}) @@ -336,7 +359,6 @@ def combine_files_with_network(self): style='background-color:#eeffdd') self.dialog.confirm_value.connect(self.on_fileselection_dialog_confirm) self.dialog.cancel_dialog.connect(self.on_dialog_cancel) - self.dialog.show(self) def read_files(self): @@ -422,7 +444,8 @@ def query_net(self, widget): self.query_the_network() def query_the_network(self): - ''' Query the semantic network ''' + ''' Query the semantic network.''' + subject = 'subject' if self.gel_net is None: print('First create a semantic network. Then query again.') else: @@ -431,11 +454,11 @@ def query_the_network(self): if self.q_view is None: # Create a query view object - self.q_view = Query_view(self.gel_net, self) + self.q_view = Query_view(self, subject) # Specify a query window and enable spefiying a query via GUI self.q_view.Define_query_window() else: - self.views_noteb.select_by_name('Search') + self.views_noteb.select_by_name(self.search_name[self.GUI_lang_index]) def Set_reply_language(self, reply_lang_name): ''' Set the reply language (name, uid, reply_lang_pref_uids) @@ -568,6 +591,8 @@ def Determine_name_in_context(self, obj, base_or_inverse='normal'): is_a = ['is a ', 'is een '] full_def = is_a[self.GUI_lang_index] + super_name + ' ' + part_def else: + if part_def == None: + part_def = '' full_def = part_def return lang_name, comm_name, obj_name, full_def @@ -576,7 +601,7 @@ def Close_tag(self, widget, tabbox, ref_widget_tab_name): ''' Close the tab in tabbox in widget with the specified tab_name''' # tabbox.select_by_name(ref_widget_tab_name) tabbox.remove_tab_by_name(ref_widget_tab_name) - if ref_widget_tab_name == 'Search': + if ref_widget_tab_name in self.search_name: self.q_view = None @@ -598,7 +623,7 @@ class Network(): ''' Dummy class for testing only.''' def __init__(self): GUI_lang_index = 0 - net_name = 'Sementic Newtork' + net_name = 'Semantic Newtork' self.gel_net = Semantic_network(GUI_lang_index, net_name) def build_network(self):