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

New transduction package: add prefix_handle module

parent ab8355fc
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/python3.10
# -*-coding:Utf-8 -*
#==============================================================================
# TENET: Naming Computer
#------------------------------------------------------------------------------
# Class grouping methods to compute URI for semantic nets (and their
# attributes)
#==============================================================================
from rdflib import Graph
from rdflib import Namespace
from rdflib.namespace import NamespaceManager
#==============================================================================
# Prefix Definition
#==============================================================================
COMMON_PREFIX_DICT = {
'xsd': 'http://www.w3.org/2001/XMLSchema#',
'owl': 'http://www.w3.org/2002/07/owl#',
'rdf': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
'rdfs': 'http://www.w3.org/2000/01/rdf-schema#',
}
TENET_PREFIX_DICT = {
'net': 'https://tenet.tetras-libre.fr/semantic-net#',
'cprm': 'https://tenet.tetras-libre.fr/config/parameters#',
'fprm': 'https://tenet.tetras-libre.fr/frame/parameters#',
'base-out': 'https://tenet.tetras-libre.fr/base-ontology#',
'ext-out': 'https://tenet.tetras-libre.fr/extract-result#'
}
AMR_STRUCTURE_PREFIX_DICT = {
'ns1': 'http://amr.isi.edu/frames/ld/v1.2.2/',
'ns2': 'http://amr.isi.edu/rdf/amr-terms#',
'ns3': 'http://amr.isi.edu/rdf/core-amr#',
'ns4': 'http://amr.isi.edu/entity-types#',
'amr': 'https://amr.tetras-libre.fr/rdf/schema#'
}
#==============================================================================
# Getter Method(s)
#==============================================================================
def get_prefix_dict():
prefix_dict = {}
prefix_dict.update(COMMON_PREFIX_DICT)
prefix_dict.update(TENET_PREFIX_DICT)
prefix_dict.update(AMR_STRUCTURE_PREFIX_DICT)
return prefix_dict
def get_prefix_list():
prefix_list = []
prefix_list += COMMON_PREFIX_DICT.items()
prefix_list += TENET_PREFIX_DICT.items()
prefix_list += AMR_STRUCTURE_PREFIX_DICT.items()
return prefix_list
#==============================================================================
# Namespace Update Method(s)
#==============================================================================
def update_graph_namespacemanager(graph):
prefix_list = get_prefix_list()
for prefix, uri in prefix_list:
graph.bind(prefix, Namespace(uri))
return graph
\ No newline at end of file
- WARNING - <net:atomClass_sun_s2> does not look like a valid URI, trying to serialize this will break.
This diff is collapsed.
......@@ -20,6 +20,7 @@ TEST_GRAPH = f'{INPUT_DIR_PATH}testGraph1.ttl'
from context import tenet
from tenet.febTransduction import phenomena_application_or as test_rule
from tenet.febTransduction import query_builder
from tenet.febTransduction import prefix_handle
INDENT_STR = ' '
......@@ -32,9 +33,7 @@ INDENT_STR = ' '
def load_test_graph():
print(f'\n -- Test Graph Loading')
graph = Graph()
graph.bind('amr', Namespace('https://amr.tetras-libre.fr/rdf/schema#'))
graph.bind('net', Namespace('https://tenet.tetras-libre.fr/semantic-net#'))
graph.bind('base-out', Namespace('https://tenet.tetras-libre.fr/base-ontology#'))
prefix_handle.update_graph_namespacemanager(graph)
graph.parse(TEST_GRAPH)
print(f" ----- Graph Loaded ({len(graph)})")
return graph
......
#!/usr/bin/python3.10
# -*-coding:Utf-8 -*
#==============================================================================
# TENET: Extraction Rule Test
#------------------------------------------------------------------------------
# Script to test rules under development
#==============================================================================
import subprocess, os
from rdflib import Graph
from rdflib import Namespace
from rdflib.namespace import NamespaceManager
FILE_PATH = f'{os.path.dirname(os.path.abspath(__file__))}'
INPUT_DIR_PATH = f'{FILE_PATH}/input/'
OUTPUT_DIR_PATH = f'{FILE_PATH}/output/'
TEST_GRAPH = f'{INPUT_DIR_PATH}testGraph1.ttl'
from context import tenet
from tenet.febTransduction import phenomena_application_or as test_rule
from tenet.febTransduction import prefix_handle
INDENT_STR = ' '
#==============================================================================
# Useful Methods
#==============================================================================
def load_test_graph():
print(f'\n -- Test Graph Loading')
graph = Graph()
graph.parse(TEST_GRAPH)
print(f" ----- Graph Loaded ({len(graph)})")
return graph
#==============================================================================
# Development Test
#==============================================================================
# None
#==============================================================================
# Unit Test
#==============================================================================
def unittest_get_prefix_dict():
print('\n -- Get Prefix Dict')
prefix_dict = prefix_handle.get_prefix_dict()
print(prefix_dict)
def unittest_get_prefix_list():
print('\n -- Get Prefix List')
prefix_dict = prefix_handle.get_prefix_list()
print(prefix_dict)
def unittest_add_prefix_to_graph(graph):
print('\n -- Add Prefix to Graph')
prefix_handle.update_graph_namespacemanager(graph)
for n in graph.namespace_manager.namespaces():
print(n)
#==============================================================================
# Test Script
#==============================================================================
if __name__ == '__main__':
print('\n *** Test Preparation ***')
graph = load_test_graph()
print('\n \n')
print('\n *** Development Test ***')
pass
print('\n \n')
print('\n *** Unit Test ***')
unittest_get_prefix_dict()
unittest_get_prefix_list()
unittest_add_prefix_to_graph(graph)
print('\n \n')
print('\n *** - ***')
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment