Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
tenet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tetras MARS
tenet
Commits
0f3cdfce
Commit
0f3cdfce
authored
2 years ago
by
David Rouquet
Browse files
Options
Downloads
Patches
Plain Diff
Add orginal method to create ontology
parent
20d01ea4
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
tenet/main.py
+78
-8
78 additions, 8 deletions
tenet/main.py
with
78 additions
and
8 deletions
tenet/main.py
+
78
−
8
View file @
0f3cdfce
...
@@ -110,7 +110,7 @@ def __serialize_factoid_graph(config, factoid_graph, out_file_path=None):
...
@@ -110,7 +110,7 @@ def __serialize_factoid_graph(config, factoid_graph, out_file_path=None):
#==============================================================================
#==============================================================================
# AMR Main Methods (to create an ontology)
# AMR Main Methods (to create an ontology)
- with one processing
#==============================================================================
#==============================================================================
#@timed
#@timed
...
@@ -168,6 +168,76 @@ def create_ontology_from_amrld_file(amrld_file_path,
...
@@ -168,6 +168,76 @@ def create_ontology_from_amrld_file(amrld_file_path,
return
ontology_turtle_string
return
ontology_turtle_string
#@timed
def
create_ontology_from_amrld_dir
(
amrld_dir_path
,
base_ontology_path
=
None
,
onto_prefix
=
None
,
out_file_path
=
None
,
technical_dir_path
=
None
):
"""
Method to create an ontology (as Turtle String) from a transduction
analysis of an AMRLD file.
Parameters
----------
amrld_file_path: a path to an AMR-LD Turtle File.
base_ontology_path: a path to a Base Ontology Turtle File if defined.
onto_prefix: the target ontology prefix if defined (if not defined a prefix based on the amrld filename is used).
out_file_path: a file path where the output ontology is written if defined (the function still outputs the string).
technical_dir_path: a dir path where some technical and log files are written if defined.
Returns
-------
Dictionary [filename -> Ontology Turtle String].
Complete Ontology Turtle String (synthesis of all ontology)
"""
logger
.
info
(
'
[TENET] Extraction Processing
'
)
# -- Process Initialization
logger
.
info
(
'
\n
=== Process Initialization ===
'
)
__set_context
()
if
onto_prefix
is
None
:
onto_prefix
=
'
DefaultId
'
base_output_dir
=
os
.
path
.
dirname
(
out_file_path
)
if
out_file_path
is
not
None
else
None
config
=
__set_config
(
OWL_CONFIG_FILE_PATH
,
'
amr
'
,
amrld_dir_path
,
onto_prefix
,
base_output_dir
,
technical_dir_path
)
assert
os
.
path
.
exists
(
amrld_dir_path
),
f
'
input directory does not exists (
{
amrld_dir_path
}
)
'
__count_number_of_graph
(
config
)
# -- Extraction Processing
logger
.
info
(
'
\n
=== Extraction Processing ===
'
)
sentence_dir
=
config
.
source_sentence_file
sentence_count
=
0
result_triple_list
=
[]
for
sentence_file
in
glob
.
glob
(
sentence_dir
,
recursive
=
True
):
sentence_count
+=
1
logger
.
info
(
f
'
*** sentence
{
sentence_count
}
***
'
)
config
.
sentence_output_dir
=
f
'
-
{
sentence_count
}
'
new_triple_list
=
__apply_extraction
(
config
,
sentence_file
)
result_triple_list
.
extend
(
new_triple_list
)
# -- Final Ontology Generation (factoid_graph)
logger
.
info
(
'
\n
=== Final Ontology Generation ===
'
)
factoid_graph
=
__generate_final_ontology
(
result_triple_list
)
ontology_turtle_string
=
__serialize_factoid_graph
(
config
,
factoid_graph
,
out_file_path
)
# -- Done
logger
.
info
(
'
\n
=== Done ===
'
)
if
config
.
technical_dir_path
is
not
None
:
log_file_name
=
'
tenet.log
'
dest_file_path
=
f
'
{
config
.
technical_dir_path
}{
log_file_name
}
'
shutil
.
copy
(
log_file_name
,
dest_file_path
)
return
ontology_turtle_string
#==============================================================================
# AMR Main Methods (to create an ontology) - Multiprocessing
#==============================================================================
global
result_triple_queue
global
result_triple_queue
global
sentence_file_list
global
sentence_file_list
...
@@ -197,7 +267,7 @@ def pool_function(arg_dic):
...
@@ -197,7 +267,7 @@ def pool_function(arg_dic):
#@timed
#@timed
def
create_ontology_from_amrld_dir
(
amrld_dir_path
,
def
create_ontology_from_amrld_dir
_with_multiprocessing
(
amrld_dir_path
,
base_ontology_path
=
None
,
base_ontology_path
=
None
,
onto_prefix
=
None
,
onto_prefix
=
None
,
out_file_path
=
None
,
out_file_path
=
None
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment