Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
Requirement Formalization Tool
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Thodoris Nestoridis
Requirement Formalization Tool
Commits
4f05584b
Commit
4f05584b
authored
Feb 05, 2021
by
Thodoris Nestoridis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
find Main syntax from Ontology (completed)
parent
17ba36dc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
182 additions
and
4 deletions
+182
-4
main_req.py
reqtool/reqman/api/reqman/apps/reqtool/models/main_req.py
+3
-1
parse_ontologies.py
...reqman/apps/reqtool/rest_api/services/parse_ontologies.py
+179
-3
No files found.
reqtool/reqman/api/reqman/apps/reqtool/models/main_req.py
View file @
4f05584b
...
...
@@ -6,7 +6,9 @@ from pygments import highlight
from
reqman.apps.reqtool.rest_api.services.parse_ontologies
import
*
findsubclass
()
find_subclass_domain_range
()
#MAIN SYNTAX
#print(get_main_sytax())
MAIN_CHOICES
=
(
(
""
,
""
),
(
"M1"
,
"M1 : system/function shall [not] set [<quantifier>] item [to stateValue]"
),
(
"M2"
,
"M2 : system/function shall [not] set state to stateValue"
),
...
...
reqtool/reqman/api/reqman/apps/reqtool/rest_api/services/parse_ontologies.py
View file @
4f05584b
from
rdflib
import
Graph
from
rdflib.namespace
import
RDFS
,
URIRef
,
RDF
from
rdflib
import
Graph
,
BNode
from
rdflib.namespace
import
RDFS
from
rdflib
import
ConjunctiveGraph
,
URIRef
,
RDFS
,
RDF
,
Namespace
#from subprocess import call
#call("./../../Ontologies/s-get http://155.207.131.19:3030/Mokos_18_1_7_47/data default >> ../../Ontologies/data.ttl", shell=True)
Ontology_file
=
"../../Ontologies/Mokos_18_1_7_47.ttl"
subClass_instances
=
"../../Ontologies/instances_subclass.txt"
list_of_DSO
=
[
"http://delab.csd.auth.gr/ontologies/2018/DSO#"
,
"http://delab.csd.auth.gr/ontologies/2018/DSO-AOCS#"
,
"http://delab.csd.auth.gr/ontologies/2018/DSO-AOCS-instances#"
]
list_of_RMO
=
[
"RMO"
,
"RMO-instances"
,
"DSO-AOCS-instances"
,
"<http://delab.csd.auth.gr/ontologies/2018/RDO-instances"
]
...
...
@@ -13,7 +15,7 @@ list_of_RMO = ["RMO", "RMO-instances", "DSO-AOCS-instances", "<http://delab.csd.
g
=
Graph
()
g
.
load
(
Ontology_file
,
format
=
"turtle"
)
def
find
subclass
():
def
find
_subclass_domain_range
():
file2
=
open
(
r"../../Ontologies/instances.txt"
,
"w+"
)
for
subj
,
obj
in
g
.
subject_objects
(
predicate
=
RDFS
.
subClassOf
):
...
...
@@ -27,6 +29,14 @@ def findsubclass():
file2
.
write
(
subClass
)
def
findsubclass
():
file2
=
open
(
subClass_instances
,
"w+"
)
for
subj
,
obj
in
g
.
subject_objects
(
predicate
=
RDFS
.
subClassOf
):
subClass
=
subj
+
"$"
+
obj
+
"
\n
"
file2
.
write
(
subClass
)
'''Get Instaces - return tuple'''
def
get_instances
(
keyword
):
in_list
=
[]
out_list
=
[]
...
...
@@ -45,3 +55,169 @@ def get_instances(keyword):
return
tuple
((
str
(
n
),
str
(
n
))
for
n
in
(
in_list
+
out_list
))
'''Get Instaces - return list'''
def
get_instances_list
(
keyword
):
findsubclass
()
an_list
=
[]
with
open
(
subClass_instances
)
as
f
:
for
data
in
f
:
if
(
data
.
strip
())
.
endswith
(
keyword
):
spliter_1
=
data
.
split
(
'$'
)
spliter_2
=
spliter_1
[
0
]
.
split
(
"#"
)
an_list
.
append
(
spliter_2
[
len
(
spliter_2
)
-
1
])
return
an_list
'''Find Boilerplate subject of each main - return list'''
def
get_subjects
(
bnodes_uriref
):
setOfElems
=
set
()
duplicate_uri
=
[]
bnodes
=
[]
rdf_syntax
=
'http://www.w3.org/1999/02/22-rdf-syntax-ns#nil'
for
elem
in
range
(
len
(
bnodes_uriref
)):
if
not
bnodes_uriref
[
elem
]
in
setOfElems
:
setOfElems
.
add
(
bnodes_uriref
[
elem
])
else
:
duplicate_uri
.
append
(
bnodes_uriref
[
elem
])
if
rdf_syntax
==
str
(
bnodes_uriref
[
elem
])
:
bnodes
=
bnodes_uriref
[:
elem
]
try
:
duplicate_uri
.
remove
(
URIRef
(
rdf_syntax
))
except
:
pass
subject_list
=
[]
for
i
in
duplicate_uri
:
if
i
in
bnodes
:
spliter
=
str
(
i
)
.
split
(
"#"
)
subject_list
.
append
(
str
(
spliter
[
1
]))
return
(
subject_list
)
'''Find Boilerplate classes between subject and verb - return list'''
def
get_related_to_subject
(
bnodes_uriref
):
related_to_subject_list
=
[]
bnodes_uriref
=
[
str
(
i
)
for
i
in
bnodes_uriref
]
for
rel_to_sub
in
bnodes_uriref
:
if
"isRelatedToSubject"
in
rel_to_sub
:
tmp
=
rel_to_sub
.
split
(
"isRelatedToSubject"
)
if
tmp
[
1
]
!=
''
:
related_to_subject_list
.
append
(
tmp
[
1
])
return
(
related_to_subject_list
)
'''Find Boilerplate Verb - return list'''
def
get_verb
(
bnodes_uriref
):
verb_list
=
[]
bnodes_uriref
=
[
str
(
i
)
for
i
in
bnodes_uriref
]
for
rel_to_sub
in
bnodes_uriref
:
if
"LO"
in
rel_to_sub
:
tmp
=
rel_to_sub
.
split
(
"#"
)
if
tmp
[
1
]
!=
''
:
verb_list
.
append
(
tmp
[
1
])
return
(
verb_list
)
'''Check if Boilerplate has quantifier - return list'''
def
check_quantifier
(
bnodes_uriref
):
bnodes_uriref
=
[
str
(
i
)
for
i
in
bnodes_uriref
]
quantity
=
[(
rel_to_sub
)
for
rel_to_sub
in
bnodes_uriref
if
"isRelatedToQuantity"
in
rel_to_sub
]
uom
=
[(
rel_to_sub
)
for
rel_to_sub
in
bnodes_uriref
if
"isRelatedtoUOM"
in
rel_to_sub
]
if
quantity
and
uom
:
return
True
'''Find Boilerplate Attribute - return list'''
def
get_attribute
(
bnodes_uriref
,
subjects
,
related_subjects
,
verbs
):
bnodes
=
[]
attribute_list
=
[]
bnodes_uriref
=
[
str
(
i
)
for
i
in
bnodes_uriref
]
for
attribute
in
bnodes_uriref
:
if
"isRelatedToSubject"
in
attribute
:
pass
elif
"isRelatedTo"
in
attribute
:
tmp
=
attribute
.
split
(
"#"
)
if
tmp
[
1
]
!=
''
:
tmp
=
tmp
[
1
]
.
split
(
"isRelatedTo"
)
attribute_list
.
append
(
tmp
[
1
])
#to be deleted in only exist isRelatedTo
elif
"isRelatedto"
in
attribute
:
tmp
=
attribute
.
split
(
"#"
)
if
tmp
[
1
]
!=
''
:
tmp
=
tmp
[
1
]
.
split
(
"isRelatedto"
)
attribute_list
.
append
(
tmp
[
1
])
attribute_list
=
list
(
filter
((
"Action"
)
.
__ne__
,
attribute_list
))
attribute_list
=
list
(
filter
((
"Attribute"
)
.
__ne__
,
attribute_list
))
attribute_list
=
list
(
filter
((
"Quantity"
)
.
__ne__
,
attribute_list
))
attribute_list
=
list
(
filter
((
"UOM"
)
.
__ne__
,
attribute_list
))
#discuss with kostas if this needed
attribute_list
=
list
(
filter
((
"TraversingConcept"
)
.
__ne__
,
attribute_list
))
tmp_list
=
[]
for
i
in
bnodes_uriref
:
if
not
"isRelatedTo"
in
i
:
if
not
"isRelatedto"
in
i
:
tmp
=
i
.
split
(
"#"
)
if
tmp
[
1
]
!=
''
:
tmp_list
.
append
(
tmp
[
1
])
tmp_list
=
list
(
filter
((
"nil"
)
.
__ne__
,
tmp_list
))
tmp_list
=
list
(
filter
((
"Restriction"
)
.
__ne__
,
tmp_list
))
tmp_list
=
list
(
filter
((
"Class"
)
.
__ne__
,
tmp_list
))
tmp_list
=
list
(
filter
((
"Action"
)
.
__ne__
,
tmp_list
))
tmp_list
=
list
(
filter
((
"Quantity"
)
.
__ne__
,
tmp_list
))
tmp_list
=
list
(
filter
((
"UnitOfMeasurement"
)
.
__ne__
,
tmp_list
))
for
i
in
subjects
:
tmp_list
=
list
(
filter
((
i
)
.
__ne__
,
tmp_list
))
for
i
in
related_subjects
:
tmp_list
=
list
(
filter
((
i
)
.
__ne__
,
tmp_list
))
for
i
in
verbs
:
tmp_list
=
list
(
filter
((
i
)
.
__ne__
,
tmp_list
))
res
=
attribute_list
+
tmp_list
res
=
list
(
dict
.
fromkeys
(
res
))
return
(
res
)
'''Find Main syntax - return a dict with the syntax'''
def
get_main_sytax
():
get_main
=
get_instances_list
(
"RBO#Main"
)
main_dict
=
{}
for
main
in
get_main
:
bnodes
=
[]
p
=
URIRef
(
"http://delab.csd.auth.gr/ontologies/2018/RBO#"
+
main
)
for
s
,
p
,
o
in
g
.
triples
((
p
,
None
,
None
)):
if
isinstance
(
o
,
BNode
):
bnodes
.
append
(
o
)
bnodes
.
sort
()
for
bn
in
bnodes
:
for
objects
in
g
.
objects
(
subject
=
BNode
(
bn
)):
if
isinstance
(
objects
,
BNode
):
bnodes
.
append
(
objects
)
bnodes
.
sort
()
bnodes_uriref
=
[]
for
bn
in
bnodes
:
for
objects
in
g
.
objects
(
subject
=
BNode
(
bn
)):
if
isinstance
(
objects
,
URIRef
):
bnodes_uriref
.
append
(
objects
)
main_dict
[
main
]
=
{}
main_dict
[
main
][
"Subject"
]
=
get_subjects
(
bnodes_uriref
)
main_dict
[
main
][
"Related_to_Subject"
]
=
get_related_to_subject
(
bnodes_uriref
)
main_dict
[
main
][
"Verbs"
]
=
get_verb
(
bnodes_uriref
)
main_dict
[
main
][
"Quantifier"
]
=
check_quantifier
(
bnodes_uriref
)
main_dict
[
main
][
"Attributes"
]
=
get_attribute
(
bnodes_uriref
,
main_dict
[
main
][
"Subject"
],
main_dict
[
main
][
"Related_to_Subject"
],
main_dict
[
main
][
"Verbs"
])
return
main_dict
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment