Skip to content
Snippets Groups Projects
Commit 47fb5d8e authored by Aurélien Lamercerie's avatar Aurélien Lamercerie
Browse files

Add Structure Builder (and update CTS)

parent d5091916
No related branches found
No related tags found
No related merge requests found
...@@ -32,7 +32,7 @@ rule_set['create-atom-class-net'] = { ...@@ -32,7 +32,7 @@ rule_set['create-atom-class-net'] = {
'comment': "Create Atom Class Net from AMR Term Concept", 'comment': "Create Atom Class Net from AMR Term Concept",
'construction': f""" 'construction': f"""
{atom_class_net.construct(base_node='?leaf1', {atom_class_net.construct(base_node='?leaf1',
structure='?sentenceRef', structure=structure.sentence_ref,
class_name='?conceptName')} class_name='?conceptName')}
{atom_class_net.propagate_relations()} {atom_class_net.propagate_relations()}
...@@ -46,9 +46,7 @@ rule_set['create-atom-class-net'] = { ...@@ -46,9 +46,7 @@ rule_set['create-atom-class-net'] = {
?leaf1Concept rdfs:subClassOf amr:AMR_Term_Concept. ?leaf1Concept rdfs:subClassOf amr:AMR_Term_Concept.
?leaf1Concept amr:label ?conceptName. ?leaf1Concept amr:label ?conceptName.
# -- Identify structure {structure.identify()}
?root a amr:AMR_Root ;
amr:hasSentenceID ?sentenceRef.
{atom_class_net.identify_relations_for_propagation('?leaf1')} {atom_class_net.identify_relations_for_propagation('?leaf1')}
""", """,
...@@ -69,7 +67,7 @@ rule_set['create-individual-net-1'] = { ...@@ -69,7 +67,7 @@ rule_set['create-individual-net-1'] = {
" (2) without link to domain edge"), " (2) without link to domain edge"),
'construction': f""" 'construction': f"""
{individual_net.construct(base_node='?baseLeaf', {individual_net.construct(base_node='?baseLeaf',
structure='?sentenceRef', structure=structure.sentence_ref,
mother_class_net='?classNet', mother_class_net='?classNet',
individual_label='?valueLabel')} individual_label='?valueLabel')}
...@@ -89,9 +87,7 @@ rule_set['create-individual-net-1'] = { ...@@ -89,9 +87,7 @@ rule_set['create-individual-net-1'] = {
net:coverBaseNode ?baseLeaf ; net:coverBaseNode ?baseLeaf ;
net:hasClassName ?conceptName. net:hasClassName ?conceptName.
# -- Identify structure {structure.identify()}
?root a amr:AMR_Root ;
amr:hasSentenceID ?sentenceRef.
{individual_net.identify_relations_for_propagation('?baseLeaf')} {individual_net.identify_relations_for_propagation('?baseLeaf')}
""", """,
...@@ -111,7 +107,7 @@ rule_set['create-atom-property-net-1'] = { ...@@ -111,7 +107,7 @@ rule_set['create-atom-property-net-1'] = {
" (1) from AMR Predicat Concept"), " (1) from AMR Predicat Concept"),
'construction': f""" 'construction': f"""
{atom_property_net.construct(base_node='?baseLeaf', {atom_property_net.construct(base_node='?baseLeaf',
structure='?sentenceRef', structure=structure.sentence_ref,
core_role='true', core_role='true',
target_argument_node='?argLeaf', target_argument_node='?argLeaf',
property_type='owl:ObjectProperty', property_type='owl:ObjectProperty',
...@@ -135,9 +131,7 @@ rule_set['create-atom-property-net-1'] = { ...@@ -135,9 +131,7 @@ rule_set['create-atom-property-net-1'] = {
?relation amr:hasAmrRole ?someArgRole. ?relation amr:hasAmrRole ?someArgRole.
}} }}
# -- Identify structure {structure.identify()}
?root a amr:AMR_Root ;
amr:hasSentenceID ?sentenceRef.
{atom_property_net.identify_relations_for_propagation('?baseLeaf')} {atom_property_net.identify_relations_for_propagation('?baseLeaf')}
""", """,
...@@ -297,7 +291,7 @@ rule_set['create-phenomena-net-1'] = { ...@@ -297,7 +291,7 @@ rule_set['create-phenomena-net-1'] = {
'comment': ("Create Phenomena Net from AMR Relation Concept"), 'comment': ("Create Phenomena Net from AMR Relation Concept"),
'construction': f""" 'construction': f"""
{phenomena_net.construct(base_node='?baseLeaf', {phenomena_net.construct(base_node='?baseLeaf',
structure='?sentenceRef', structure=structure.sentence_ref,
core_role='true', core_role='true',
target_argument_node='?argLeaf', target_argument_node='?argLeaf',
phenomena_type='?relationConceptPhenomena', phenomena_type='?relationConceptPhenomena',
...@@ -318,9 +312,7 @@ rule_set['create-phenomena-net-1'] = { ...@@ -318,9 +312,7 @@ rule_set['create-phenomena-net-1'] = {
?baseLeaf ?relation ?argLeaf. ?baseLeaf ?relation ?argLeaf.
?relation amr:hasAmrRole ?someArgRole. ?relation amr:hasAmrRole ?someArgRole.
# -- Identify structure {structure.identify()}
?root a amr:AMR_Root ;
amr:hasSentenceID ?sentenceRef.
{phenomena_net.identify_relations_for_propagation('?baseLeaf')} {phenomena_net.identify_relations_for_propagation('?baseLeaf')}
""", """,
...@@ -345,7 +337,7 @@ if __name__ == '__main__': ...@@ -345,7 +337,7 @@ if __name__ == '__main__':
test_query_1 = f"""[...] test_query_1 = f"""[...]
CONSTRUCT {{ CONSTRUCT {{
{atom_property_net.construct(base_node='?baseLeaf', {atom_property_net.construct(base_node='?baseLeaf',
structure='?sentenceRef', structure=structure.sentence_ref,
core_role='true', core_role='true',
target_argument_node='?argLeaf', target_argument_node='?argLeaf',
property_type='owl:ObjectProperty', property_type='owl:ObjectProperty',
...@@ -364,7 +356,7 @@ if __name__ == '__main__': ...@@ -364,7 +356,7 @@ if __name__ == '__main__':
{{node1.concept}} amr:label ?conceptName. {{node1.concept}} amr:label ?conceptName.
{{node1.variable}} amr:label ?varLabel. {{node1.variable}} amr:label ?varLabel.
{{structure.identify()}} {structure.identify()}
{atom_property_net.identify_relations_for_propagation('?baseLeaf')} {atom_property_net.identify_relations_for_propagation('?baseLeaf')}
...@@ -379,7 +371,7 @@ if __name__ == '__main__': ...@@ -379,7 +371,7 @@ if __name__ == '__main__':
test_query_2 = f"""[...] test_query_2 = f"""[...]
CONSTRUCT {{ CONSTRUCT {{
{individual_net.construct(base_node='?baseLeaf', {individual_net.construct(base_node='?baseLeaf',
structure='?sentenceRef', structure=structure.sentence_ref,
mother_class_net='?classNet', mother_class_net='?classNet',
individual_label='?valueLabel')} individual_label='?valueLabel')}
......
...@@ -13,6 +13,14 @@ ...@@ -13,6 +13,14 @@
#============================================================================== #==============================================================================
from .element.net import * from .element.net import *
from .element.structure import *
#==============================================================================
# AMR Structure Builder(s)
#==============================================================================
structure = Structure()
#============================================================================== #==============================================================================
......
#!/usr/bin/python3.10
# -*-coding:Utf-8 -*
#==============================================================================
# TENET: Structure Query Builder
#------------------------------------------------------------------------------
# Class to generate SPARQL query parts related to structure
#==============================================================================
#==============================================================================
# Importing required modules
#==============================================================================
# --
#==============================================================================
# Data Repository
#==============================================================================
# -- Reference Table
NET_TYPE_TABLE = { # *** [type_name: type_id] ***
'default': 'Net',
'atomClass': 'Atom_Class_Net',
'individual': 'Individual_Net',
'atomProperty': 'Atom_Property_Net',
'phenomena': 'Phenomena_Net'
}
PREDICATE_TABLE = { # *** [attribute_reference: attribute_predicate] ***
'structure': 'hasStructure',
'class_name': 'hasClassName',
'mother_class_net': 'hasMotherClassNet',
'individual_label': 'hasIndividualLabel',
'core_role': 'isCoreRoleLinked',
'target_argument_node': 'targetArgumentNode',
'property_type': 'hasPropertyType',
'property_name': 'hasPropertyName',
'property_name01': 'hasPropertyName01',
'property_name10': 'hasPropertyName10',
'property_name12': 'hasPropertyName12',
'phenomena_type': 'hasPhenomenaType',
'phenomena_ref': 'hasPhenomenaRef'
}
# -- Default Value(s)
DEFAULT_ATTRIBUTE_VALUE = f'\"NA\"'
# -- Useful Constant(s)
TRIPLE_ENDING_STR = '\n '
#==============================================================================
# Net Class
#==============================================================================
class Structure:
""" Class to generate SPARQL query parts related to structure.
"""
#--------------------------------------------------------------------------
# Constructor(s)
#--------------------------------------------------------------------------
def __init__(self):
# -- Structure Attribute(s)
self.sentence_ref = f'?sentenceRef'
#--------------------------------------------------------------------------
# Method(s) to build 'Clause' parts
#--------------------------------------------------------------------------
def identify(self):
return f"""
# -- Identify structure
?root a amr:AMR_Root.
?root amr:hasSentenceID ?sentenceRef.
"""
#==============================================================================
# Development Test
#==============================================================================
if __name__ == '__main__':
print('\n' + ' *** Development Test ***')
print('\n' + ' -- test: Atom Class Net')
structure = Structure()
print(structure)
print('\n' + ' -- test: update a test query')
test_query= f"""[...]
CONSTRUCT {{
[{{atom_class_net.construct('?node1',
structure={structure.sentence_ref},
class_name='?leaf1ConceptLabel')}}
}}
WHERE {{
clause_1
clause_2
{structure.identify()}
}}
"""
print(test_query)
print('\n' + ' *** - ***')
\ No newline at end of file
...@@ -66,7 +66,7 @@ ...@@ -66,7 +66,7 @@
- DEBUG - --- Export work graph as turtle - DEBUG - --- Export work graph as turtle
- DEBUG - ----- Work graph file: ./output/SolarSystemDev1-20221215/SolarSystemDev1-1/SolarSystemDev1.ttl - DEBUG - ----- Work graph file: ./output/SolarSystemDev1-20221215/SolarSystemDev1-1/SolarSystemDev1.ttl
- DEBUG - --- Ending Structure Preparation - DEBUG - --- Ending Structure Preparation
- DEBUG - ----- Total Execution Time = 0:00:00.122984 - DEBUG - ----- Total Execution Time = 0:00:00.127085
- INFO - -- Loading Extraction Scheme (amr_scheme_1) - INFO - -- Loading Extraction Scheme (amr_scheme_1)
- DEBUG - ----- Step number: 3 - DEBUG - ----- Step number: 3
- INFO - -- Loading Extraction Rules (amr_ctr/*) - INFO - -- Loading Extraction Rules (amr_ctr/*)
...@@ -216,8 +216,8 @@ ...@@ -216,8 +216,8 @@
- INFO - - INFO -
*** Execution Time *** *** Execution Time ***
----- Function: apply (lib.tenet_extraction) ----- Function: apply (lib.tenet_extraction)
----- Total Time: 0:00:07.695899 ----- Total Time: 0:00:07.567600
----- Process Time: 0:00:07.663001 ----- Process Time: 0:00:07.544648
*** - *** *** - ***
- INFO - === Final Ontology Generation === - INFO - === Final Ontology Generation ===
- INFO - -- Making complete factoid graph by merging sentence factoid graphs - INFO - -- Making complete factoid graph by merging sentence factoid graphs
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment