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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tetras MARS
tenet
Commits
52e1f801
Commit
52e1f801
authored
3 years ago
by
Aurélien Lamercerie
Browse files
Options
Downloads
Patches
Plain Diff
Add command EXTRACT
parent
4dbf0387
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
CHANGELOG
+7
-11
7 additions, 11 deletions
CHANGELOG
extract.py
+240
-0
240 additions, 0 deletions
extract.py
frame/ontology-parameters.ttl
+1
-1
1 addition, 1 deletion
frame/ontology-parameters.ttl
with
248 additions
and
12 deletions
CHANGELOG
+
7
−
11
View file @
52e1f801
...
@@ -5,22 +5,18 @@ All notable changes to this project will be documented in this file.
...
@@ -5,22 +5,18 @@ All notable changes to this project will be documented in this file.
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
## [0.2.0] - 2021-xx-xx TODO
## [0.1.1] - 2021-08-24
### Added
### Added
-
Implementing t
ran
s
duction
s
cheme
s as a SPARQL query (using sparql-wrapper
)
-
Compositionnal T
randu
s
ction
S
cheme
(CTS
)
-
Saving queries with XML files (cdata)
-
Command **_extract.py_** to analyse one sentence
-
Loading
corpus
as RDF ontology
-
Init
corpus
ABCD (dev test)
### Changed
### Changed
- TODO
- ontologies in config and frame
### Fix
- TODO
-------------------------------------------------------------------------------
## [0.1.0] - 2021-08-10
## [0.1.0] - 2021-08-10 IN PROGRESS
### Added
### Added
- Init project
- Init project
...
...
This diff is collapsed.
Click to expand it.
extract.py
0 → 100644
+
240
−
0
View file @
52e1f801
#!/usr/bin/python3.5
# -*-coding:Utf-8 -*
#==============================================================================
# TENET: extract
#------------------------------------------------------------------------------
# Command to extract data from corpus and generate targetted ontology
# following frame ontology
#==============================================================================
#==============================================================================
# Importing required modules
#==============================================================================
from
rdflib
import
Graph
#==============================================================================
# Parameters
#==============================================================================
# Working directories
CONFIG_DIR
=
"
config/
"
FRAME_DIR
=
"
frame/
"
CORPUS_DIR
=
"
corpus/
"
CTS_DIR
=
"
cts/
"
# Config Definition
schema_file
=
"
unl-rdf-schema.ttl
"
semantic_net_file
=
"
semantic-net.ttl
"
c_param_file
=
"
config-parameters.ttl
"
req_onto_file
=
"
requirement-ontology.ttl
"
sys_onto_file
=
"
system-ontology.ttl
"
f_param_file
=
"
ontology-parameters.ttl
"
# Dev Tests
corpus
=
"
CCTP-SRSA-IP-20210625/
"
req_300_file
=
"
SRSA-IP_STB_PHON_00300.ttl
"
#==============================================================================
# Utility
#==============================================================================
def
read_query
(
cts_group
,
query_ref
):
query_file
=
CTS_DIR
+
cts_group
+
str
(
query_ref
)
+
"
.cts
"
with
open
(
query_file
,
"
r
"
)
as
file
:
return
file
.
read
()
#==============================================================================
# Graph Initialization
#==============================================================================
def
load_config
(
g
):
print
(
"
-- Configuration Loading:
"
)
file_ref
=
CONFIG_DIR
+
schema_file
g
.
parse
(
file_ref
)
print
(
"
----- RDF Schema (
"
+
str
(
len
(
g
))
+
"
)
"
)
file_ref
=
CONFIG_DIR
+
semantic_net_file
g
.
parse
(
file_ref
)
print
(
"
----- Semantic Net Definition (
"
+
str
(
len
(
g
))
+
"
)
"
)
file_ref
=
CONFIG_DIR
+
c_param_file
g
.
parse
(
file_ref
)
print
(
"
----- Config Parameter Definition (
"
+
str
(
len
(
g
))
+
"
)
"
)
def
load_frame
(
g
):
print
(
"
-- Frame Ontology Loading:
"
)
file_ref
=
FRAME_DIR
+
req_onto_file
g
.
parse
(
file_ref
)
print
(
"
----- Requirement Frame Ontology (
"
+
str
(
len
(
g
))
+
"
)
"
)
file_ref
=
FRAME_DIR
+
sys_onto_file
g
.
parse
(
file_ref
)
print
(
"
----- System Frame Ontology (
"
+
str
(
len
(
g
))
+
"
)
"
)
file_ref
=
FRAME_DIR
+
f_param_file
g
.
parse
(
file_ref
)
print
(
"
----- Ontology Parameters (
"
+
str
(
len
(
g
))
+
"
)
"
)
def
load_sentence
(
g
,
sentence_file
):
print
(
"
-- Sentence Loading:
"
)
file_ref
=
CORPUS_DIR
+
corpus
+
sentence_file
g
.
parse
(
file_ref
)
print
(
"
-----
"
+
sentence_file
+
"
(
"
+
str
(
len
(
g
))
+
"
)
"
)
#==============================================================================
# Graph Preprocessing
#==============================================================================
def
bypass_reification
(
g
):
print
(
"
-- Bypass Reification:
"
)
cts_group
=
"
preprocessing/reification/
"
queryString
=
read_query
(
cts_group
,
201
)
g
.
update
(
queryString
)
print
(
"
----- update to extend UNL relation (
"
+
str
(
len
(
g
))
+
"
)
"
)
queryString
=
read_query
(
cts_group
,
202
)
g
.
update
(
queryString
)
print
(
"
----- update to bypass scopes (
"
+
str
(
len
(
g
))
+
"
)
"
)
#==============================================================================
# Net Extension (CTS Application)
#==============================================================================
def
extract_entity
(
g
):
print
(
"
-- Net Extension to Extract Entity:
"
)
cts_group
=
"
net_extension/entity_extraction/
"
queryString
=
read_query
(
cts_group
,
301
)
g
.
update
(
queryString
)
print
(
"
----- update to create Entity net (
"
+
str
(
len
(
g
))
+
"
)
"
)
print
(
"
-------- net instances:
"
)
for
r
in
g
.
query
(
read_query
(
"
selection/
"
,
101
)):
print
(
"
--------
"
+
f
"
{
r
.
net
}
"
)
queryString
=
read_query
(
cts_group
,
302
)
g
.
update
(
queryString
)
print
(
"
----- update to create Entity net (
"
+
str
(
len
(
g
))
+
"
)
"
)
print
(
"
-------- net instances:
"
)
for
r
in
g
.
query
(
read_query
(
"
selection/
"
,
101
)):
print
(
"
--------
"
+
f
"
{
r
.
net
}
"
)
queryString
=
read_query
(
cts_group
,
303
)
g
.
update
(
queryString
)
print
(
"
----- update to create Entity net (
"
+
str
(
len
(
g
))
+
"
)
"
)
print
(
"
-------- net instances:
"
)
for
r
in
g
.
query
(
read_query
(
"
selection/
"
,
101
)):
print
(
"
--------
"
+
f
"
{
r
.
net
}
"
)
queryString
=
read_query
(
cts_group
,
304
)
g
.
update
(
queryString
)
print
(
"
----- update to create Entity net (
"
+
str
(
len
(
g
))
+
"
)
"
)
print
(
"
-------- net instances:
"
)
for
r
in
g
.
query
(
read_query
(
"
selection/
"
,
101
)):
print
(
"
--------
"
+
f
"
{
r
.
net
}
"
)
queryString
=
read_query
(
cts_group
,
305
)
g
.
update
(
queryString
)
print
(
"
----- update to create Entity net (
"
+
str
(
len
(
g
))
+
"
)
"
)
print
(
"
-------- net instances:
"
)
for
r
in
g
.
query
(
read_query
(
"
selection/
"
,
101
)):
print
(
"
--------
"
+
f
"
{
r
.
net
}
"
)
queryString
=
read_query
(
cts_group
,
306
)
g
.
update
(
queryString
)
print
(
"
----- update to create Entity net (
"
+
str
(
len
(
g
))
+
"
)
"
)
print
(
"
-------- net instances:
"
)
for
r
in
g
.
query
(
read_query
(
"
selection/
"
,
101
)):
print
(
"
--------
"
+
f
"
{
r
.
net
}
"
)
queryString
=
read_query
(
cts_group
,
307
)
g
.
update
(
queryString
)
print
(
"
----- update to create Entity net (
"
+
str
(
len
(
g
))
+
"
)
"
)
print
(
"
-------- net instances:
"
)
for
r
in
g
.
query
(
read_query
(
"
selection/
"
,
101
)):
print
(
"
--------
"
+
f
"
{
r
.
net
}
"
)
queryString
=
read_query
(
cts_group
,
308
)
g
.
update
(
queryString
)
print
(
"
----- update to create Entity net (
"
+
str
(
len
(
g
))
+
"
)
"
)
print
(
"
-------- net instances:
"
)
for
r
in
g
.
query
(
read_query
(
"
selection/
"
,
101
)):
print
(
"
--------
"
+
f
"
{
r
.
net
}
"
)
#==============================================================================
# Ontology Generation
#==============================================================================
def
classify_entity
(
g
):
print
(
"
-- Enity Classification (From Net Ontology to System Ontology):
"
)
cts_group
=
"
generation/classification/
"
queryString
=
read_query
(
cts_group
,
401
)
g
.
update
(
queryString
)
print
(
"
----- update to create Entity net (
"
+
str
(
len
(
g
))
+
"
)
"
)
print
(
"
-------- entity classes:
"
)
for
r
in
g
.
query
(
read_query
(
"
selection/
"
,
102
)):
print
(
"
--------
"
+
f
"
{
r
.
entity
}
"
)
queryString
=
read_query
(
cts_group
,
402
)
g
.
update
(
queryString
)
print
(
"
----- update to create Entity net (
"
+
str
(
len
(
g
))
+
"
)
"
)
print
(
"
-------- entity classes:
"
)
for
r
in
g
.
query
(
read_query
(
"
selection/
"
,
102
)):
print
(
"
--------
"
+
f
"
{
r
.
entity
}
"
)
#==============================================================================
# Main Function
#==============================================================================
def
run
():
try
:
print
(
"
Tenet Processing
"
)
print
(
"
\n
"
+
"
- Graph Initialization
"
)
g
=
Graph
()
load_config
(
g
)
load_frame
(
g
)
load_sentence
(
g
,
req_300_file
)
print
(
"
\n
"
+
"
- Graph Preprocessing
"
)
bypass_reification
(
g
)
print
(
"
\n
"
+
"
- Net Extension (CTS Application)
"
)
extract_entity
(
g
)
print
(
"
\n
"
+
"
- Ontology Generation
"
)
classify_entity
(
g
)
except
:
print
(
"
!!! An exception occurred !!!
"
)
#==============================================================================
# Execution
#==============================================================================
if
__name__
==
'
__main__
'
:
run
()
This diff is collapsed.
Click to expand it.
frame/ontology-parameters.ttl
+
1
−
1
View file @
52e1f801
...
@@ -18,7 +18,7 @@ fprm:Frame_Parameters
...
@@ -18,7 +18,7 @@ fprm:Frame_Parameters
fprm:
System_Entity
fprm:
System_Entity
rdf:
type
owl:
Class
;
rdf:
type
owl:
Class
;
rdfs:
comment
"Parameters related to Entity (System Ontology)."
;
rdfs:
comment
"Parameters related to Entity (System Ontology)."
;
rdfs:
label
"
e
ntity"
;
rdfs:
label
"
E
ntity"
;
rdfs:
subClassOf
fprm:
System_Ontology
;
rdfs:
subClassOf
fprm:
System_Ontology
;
.
.
fprm:
System_Feature
fprm:
System_Feature
...
...
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