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
94573968
Commit
94573968
authored
Feb 02, 2021
by
Thodoris Nestoridis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new method for parse instances in Ontology file + changes in Prefix
parent
8aecd007
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
769 additions
and
121 deletions
+769
-121
instances.txt
reqtool/Ontologies/instances.txt
+675
-0
main_req.py
reqtool/reqman/api/reqman/apps/reqtool/models/main_req.py
+9
-16
requirements.py
...ool/reqman/api/reqman/apps/reqtool/models/requirements.py
+8
-8
suffix_req.py
reqtool/reqman/api/reqman/apps/reqtool/models/suffix_req.py
+1
-2
parse_ontologies.py
...reqman/apps/reqtool/rest_api/services/parse_ontologies.py
+27
-89
crud_ontology.py
reqtool/test_scripts/crud_ontology.py
+27
-6
instances.py
reqtool/test_scripts/instances.py
+22
-0
No files found.
reqtool/Ontologies/instances.txt
0 → 100644
View file @
94573968
This diff is collapsed.
Click to expand it.
reqtool/reqman/api/reqman/apps/reqtool/models/main_req.py
View file @
94573968
...
...
@@ -6,6 +6,7 @@ from pygments import highlight
from
reqman.apps.reqtool.rest_api.services.parse_ontologies
import
*
findsubclass
()
MAIN_CHOICES
=
(
(
""
,
""
),
(
"M1"
,
"M1 : system/function shall [not] set [<quantifier>] item [to stateValue]"
),
(
"M2"
,
"M2 : system/function shall [not] set state to stateValue"
),
...
...
@@ -26,28 +27,20 @@ MAIN_CHOICES = ( ("",""), ("M1", "M1 : system/function shall [not] set [<quant
)
#to be updated with domains from DSO
#SYSTEM_CHOICES = (("SYSTEM", "SYSTEM"), ("SYSTEM2", "SYSTEM2"))
SYSTEM_CHOICES
=
find_extra_keywords
(
"SAO:System"
,
1
)
#FUNCTION_CHOICES = (("FUNCTION", "FUNCTION"), ("FUNCTION2", "FUNCTION2"))
FUNCTION_CHOICES
=
find_extra_keywords
(
":Function"
,
1
)
+
find_extra_keywords
(
":Function"
,
2
)
SYSTEM_CHOICES
=
get_instances
(
"SAO#System"
)
FUNCTION_CHOICES
=
get_instances
(
"SAO#Function"
)
SHALL_CHOICES
=
(
(
"shall"
,
"SHALL"
),
(
"shall not"
,
"SHALL NOT"
))
QUANTIFIER_CHOICES
=
(
(
"none"
,
"NONE"
),
(
"all"
,
"ALL"
),
(
"only"
,
"ONLY"
),
(
"more than"
,
"MORE THAN"
),
(
"less than"
,
"LESS THAN"
),
(
"exactly"
,
"EXACTLY"
),
(
"at least"
,
"AT LEAST"
),
(
"at most"
,
"AT MOST"
)
)
NUMBER_UNITS_CHOICES
=
((
""
,
""
),
(
"meters"
,
"METERS"
),
(
"kilometers"
,
"KILOMETERS"
),
(
"volt"
,
"VOLT"
))
#ITEM_CHOICES = (("ITEM", "ITEM"), ("ITEM2", "ITEM2") )
ITEM_CHOICES
=
find_extra_keywords
(
"SAO:Item"
,
1
)
#STATE_VALUE_CHOICES = (("enabled", "ENABLED"), ("disabled", "DISABLED"))
STATE_VALUE_CHOICES
=
find_extra_keywords
(
":StateValue"
,
2
)
#STATE_CHOICES = (("state", "STATE"), ("state2", "STATE2"))
STATE_CHOICES
=
tuple
(
[
x
for
x
in
find_extra_keywords
(
":State"
,
2
)
if
x
not
in
STATE_VALUE_CHOICES
])
#FLOW_CHOICES = (("flow","FLOW"), ("flow2","FLOW2"))
FLOW_CHOICES
=
find_extra_keywords
(
":Flow"
,
3
)
#INTERFACE_CHOICES = (("interface","INTERFACE"), ("interface2","INTERFACE2"))
INTERFACE_CHOICES
=
find_extra_keywords
(
":Interface"
,
2
)
#CONNECTION_CHOICES = (("connection","CONNECTION"), ("connection2","CONNECTION2"))
CONNECTION_CHOICES
=
find_extra_keywords
(
":Connection"
,
2
)
ITEM_CHOICES
=
get_instances
(
"SAO#Item"
)
STATE_VALUE_CHOICES
=
get_instances
(
"SAO#StateValue"
)
STATE_CHOICES
=
get_instances
(
"SAO#State"
)
#tuple( [ x for x in find_extra_keywords(":State", 2) if x not in STATE_VALUE_CHOICES ])
FLOW_CHOICES
=
get_instances
(
"SAO#Flow"
)
INTERFACE_CHOICES
=
get_instances
(
"SAO#Interface"
)
CONNECTION_CHOICES
=
get_instances
(
"SAO#Connection"
)
VERB_CHOICES
=
((
"set"
,
"set"
),(
"send"
,
"send"
),(
"receive"
,
"receive"
),(
"ingest"
,
"ingest"
),(
"emit"
,
"emit"
),(
"perform"
,
"perform"
),(
"invoke"
,
"invoke"
),
(
"present"
,
"present"
),(
"transfer"
,
"transfer"
),(
"interact with"
,
"interact with"
),(
"have state"
,
"have state"
),(
"have substate"
,
"have substate"
),
(
"take values from"
,
"take values from"
),(
"be composed"
,
"be composed"
),(
"contain"
,
"contain"
))
...
...
reqtool/reqman/api/reqman/apps/reqtool/models/requirements.py
View file @
94573968
from
django.db
import
models
#from reqman.apps.common.models import CoreModel
from
reqman.apps.account.models
import
User
from
reqman.apps.reqtool.models.main_req
import
create_main
,
SYSTEM_OR_FUNCTION_CHOICES
,
ITEM_FLOW_FUNCTION
from
reqman.apps.reqtool.models.main_req
import
create_main
,
ITEM_CHOICES
,
STATE_VALUE_CHOICES
,
STATE_CHOICES
,
SYSTEM_CHOICES
,
SYSTEM_OR_FUNCTION_CHOICES
,
ITEM_FLOW_FUNCTION
from
reqman.apps.reqtool.models.suffix_req
import
create_suffix
from
pygments.formatters.html
import
HtmlFormatter
...
...
@@ -93,16 +93,16 @@ class Prefix(models.Model):
prefix_boilerplate
=
models
.
ForeignKey
(
Boilerplate
,
related_name
=
'prefix_boilerplate'
,
on_delete
=
models
.
CASCADE
)
prefix
=
models
.
CharField
(
choices
=
PREFIX_CHOICES
,
max_length
=
100
)
#state value constraint
item_log
=
models
.
TextField
(
max_length
=
100
,
blank
=
True
)
s
ystem_state
=
models
.
TextField
(
max_length
=
100
,
blank
=
True
)
state_value
=
models
.
TextField
(
max_length
=
100
,
blank
=
True
)
system_fun_item
=
models
.
CharField
(
choices
=
(
ITEM_CHOICES
+
SYSTEM_OR_FUNCTION_CHOICES
),
max_length
=
100
,
blank
=
True
)
s
tate_or_verb
=
models
.
CharField
(
choices
=
STATE_CHOICES
+
VERB_CHOICES
,
max_length
=
100
,
blank
=
True
)
#state_value = models.CharField(choices=STATE_VALUE_CHOICES,
max_length=100, blank=True)
#occuring functionality
sys_fun
=
models
.
CharField
(
choices
=
SYSTEM_OR_FUNCTION_CHOICES
,
max_length
=
100
,
blank
=
True
)
verb
=
models
.
CharField
(
choices
=
VERB_CHOICES
,
max_length
=
100
,
blank
=
True
)
item_function_flow
=
models
.
CharField
(
choices
=
ITEM_FLOW_FUNCTION
,
max_length
=
100
,
blank
=
True
)
#sys_fun = models.CharField(choices=
, max_length=100, blank=True)
#
verb = models.CharField(choices=VERB_CHOICES, max_length=100, blank=True)
item_function_flow
_statevalue
=
models
.
CharField
(
choices
=
ITEM_FLOW_FUNCTION
+
STATE_VALUE_CHOICES
,
max_length
=
100
,
blank
=
True
)
#Prefix value P1/P2/P3
logical_expression
=
models
.
CharField
(
choices
=
LOGICAL_EXPRESSION
,
max_length
=
100
,
blank
=
True
)
#
add extra
prefix
#
Info for
prefix
logic_connective
=
models
.
CharField
(
choices
=
LOGIC_CONNECTIVE
,
default
=
''
,
max_length
=
100
,
blank
=
True
)
simple_prefix
=
models
.
CharField
(
choices
=
SIMPLE_PREFIX_CHOICES
,
max_length
=
100
)
...
...
reqtool/reqman/api/reqman/apps/reqtool/models/suffix_req.py
View file @
94573968
...
...
@@ -20,8 +20,7 @@ NUMERICAL_AFFIRMATIVE_CHOICES = (("more than", "MORE THAN"), ("less than", "LESS
(
"at least"
,
"AT LEAST"
),
(
"at most"
,
"AT MOST"
))
NUMBER_UNITS_CHOICES
=
((
""
,
""
),
(
"meters"
,
"METERS"
),
(
"kilometers"
,
"KILOMETERS"
),
(
"volt"
,
"VOLT"
))
TIME_UNITS_CHOICES
=
((
""
,
""
),
(
"seconds"
,
"SECONDS"
),
(
"minutes"
,
"MINUTES"
),
(
"milliseconds"
,
"MILLISECONDS"
))
#FLOW_CHOICES = (("flow","FLOW"), ("flow2","FLOW2"))
FLOW_CHOICES
=
find_extra_keywords
(
":Flow"
,
3
)
FLOW_CHOICES
=
get_instances
(
"SAO#Flow"
)
S2_CHOICES
=
((
"before"
,
"BEFORE"
),
(
"after"
,
"AFTER"
))
S3_CHOICES
=
((
"every"
,
"EVERY"
),
(
"for a period of"
,
"FOR A PERIOD OF"
),
(
"within"
,
"WITHIN"
),
(
"for at least"
,
"FOR AT LEAST"
))
S4_CHOICES
=
((
"at the beginning"
,
"AT THE BEGINNING"
),
(
"at the end"
,
"AT THE END"
))
...
...
reqtool/reqman/api/reqman/apps/reqtool/rest_api/services/parse_ontologies.py
View file @
94573968
from
rdflib
import
Graph
from
rdflib.namespace
import
RDFS
#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)
...
...
@@ -8,97 +11,32 @@ list_of_DSO = ["DSO", "DSO-AOCS", "DSO-AOCS-instances"]
list_of_RMO
=
[
"RMO"
,
"RMO-instances"
,
"DSO-AOCS-instances"
,
"<http://delab.csd.auth.gr/ontologies/2018/RDO-instances"
]
'''Return the Systems and Items from the Ontologies'''
def
get_keyword
(
keyword
):
system_list
=
[]
for
dso
in
list_of_DSO
:
flag_1
,
flag_2
=
0
,
0
with
open
(
Ontology_file
)
as
f
:
for
line
in
f
:
if
line
.
startswith
(
dso
):
spliter_1
=
line
.
split
(
':'
)
spliter_2
=
spliter_1
[
1
]
.
split
(
' '
)
key
=
spliter_2
[
0
]
.
strip
()
flag_1
=
1
if
flag_1
==
1
:
if
':'
in
keyword
:
if
keyword
in
line
and
(
"subClassOf"
in
line
)
and
not
(
':comment'
in
line
or
'disjointWith'
in
line
or
'construct'
in
line
or
'label'
in
line
)
:
flag_2
=
1
elif
not
':'
in
keyword
:
keyword
=
':'
+
keyword
if
keyword
in
line
and
(
"subClassOf"
in
line
)
and
not
(
':comment'
in
line
or
'disjointWith'
in
line
or
'construct'
in
line
or
'label'
in
line
)
:
flag_2
=
1
if
flag_1
==
1
and
flag_2
==
1
:
if
(
line
.
strip
())
.
endswith
(
'.'
):
if
not
key
in
system_list
:
system_list
.
append
(
key
)
flag_1
,
flag_2
=
0
,
0
if
(
line
.
strip
())
.
endswith
(
'.'
)
and
not
((
line
.
strip
())
.
startswith
(
'-'
)
or
(
':comment'
in
line
))
:
flag_1
,
flag_2
=
0
,
0
return
system_list
#tuple((str(n), str(n)) for n in system_list)
def
findsubclass
():
file2
=
open
(
r"../../Ontologies/instances.txt"
,
"w+"
)
g
=
Graph
()
g
.
load
(
Ontology_file
,
format
=
"turtle"
)
for
subj
,
obj
in
g
.
subject_objects
(
predicate
=
RDFS
.
subClassOf
):
subClass
=
subj
+
"$"
+
obj
+
"
\n
"
file2
.
write
(
subClass
)
for
subj
,
obj
in
g
.
subject_objects
(
predicate
=
RDFS
.
domain
):
subClass
=
subj
+
"$"
+
obj
+
"
\n
"
file2
.
write
(
subClass
)
for
subj
,
obj
in
g
.
subject_objects
(
predicate
=
RDFS
.
range
):
subClass
=
subj
+
"$"
+
obj
+
"
\n
"
file2
.
write
(
subClass
)
'''Return the Flow, State, Interface, Connection from the Ontologies'''
def
get_keyword_2
(
keyword
):
system_list
=
[]
for
dso
in
list_of_RMO
:
flag_1
,
flag_2
=
0
,
0
with
open
(
Ontology_file
)
as
f
:
for
line
in
f
:
if
line
.
startswith
(
dso
):
spliter_1
=
line
.
split
(
':'
)
spliter_2
=
spliter_1
[
1
]
.
split
(
' '
)
key
=
spliter_2
[
0
]
.
strip
()
flag_1
=
1
if
flag_1
==
1
:
if
':'
in
keyword
:
if
keyword
in
line
and
(
"domain"
in
line
or
"range"
in
line
or
"a"
in
line
)
and
not
(
':comment'
in
line
or
'disjointWith'
in
line
or
'construct'
in
line
or
'label'
in
line
)
:
flag_2
=
1
elif
not
':'
in
keyword
:
keyword
=
':'
+
keyword
if
keyword
in
line
and
(
"domain"
in
line
or
"range"
in
line
or
"a"
in
line
)
and
not
(
':comment'
in
line
or
'disjointWith'
in
line
or
'construct'
in
line
or
'label'
in
line
)
:
flag_2
=
1
if
flag_1
==
1
and
flag_2
==
1
:
if
(
line
.
strip
())
.
endswith
(
'.'
):
if
not
key
in
system_list
:
system_list
.
append
(
key
)
flag_1
,
flag_2
=
0
,
0
if
(
line
.
strip
())
.
endswith
(
'.'
)
and
not
((
line
.
strip
())
.
startswith
(
'-'
)
or
(
':comment'
in
line
))
:
flag_1
,
flag_2
=
0
,
0
return
system_list
#tuple((str(n), str(n)) for n in system_list)
def
get_instances
(
keyword
):
in_list
=
[]
with
open
(
'../../Ontologies/instances.txt'
)
as
f
:
for
data
in
f
:
if
(
data
.
strip
())
.
endswith
(
keyword
):
spliter_1
=
data
.
split
(
'$'
)
spliter_2
=
spliter_1
[
0
]
.
split
(
"#"
)
in_list
.
append
(
spliter_2
[
len
(
spliter_2
)
-
1
])
return
tuple
((
str
(
n
),
str
(
n
))
for
n
in
in_list
)
def
find_extra_keywords
(
keyword
,
choice
):
third_search
=
[]
if
choice
==
1
:
first_search
=
get_keyword
(
keyword
)
second_search
=
first_search
.
copy
()
for
i
in
first_search
:
k
=
get_keyword
(
i
)
for
kl
in
k
:
if
not
kl
in
second_search
:
second_search
.
append
(
kl
)
third_search
=
second_search
.
copy
()
for
i
in
second_search
:
k
=
get_keyword
(
i
)
for
kl
in
k
:
if
not
kl
in
third_search
:
third_search
.
append
(
kl
)
if
choice
==
2
:
first_search
=
get_keyword_2
(
keyword
)
second_search
=
first_search
.
copy
()
for
i
in
first_search
:
k
=
get_keyword_2
(
i
)
for
kl
in
k
:
if
not
kl
in
second_search
:
second_search
.
append
(
kl
)
third_search
=
second_search
.
copy
()
for
i
in
second_search
:
k
=
get_keyword_2
(
i
)
for
kl
in
k
:
if
not
kl
in
third_search
:
third_search
.
append
(
kl
)
if
choice
==
3
:
third_search
=
get_keyword_2
(
keyword
)
return
tuple
((
str
(
n
),
str
(
n
))
for
n
in
third_search
)
reqtool/test_scripts/crud_ontology.py
View file @
94573968
from
rdflib
import
Graph
from
rdflib
import
Namespace
from
rdflib.namespace
import
RDF
from
rdflib
import
ConjunctiveGraph
,
URIRef
from
rdflib.namespace
import
RDFS
g
=
Graph
()
#g.parse("../Ontologies/Mokos_18_1_7_47 copy.ttl", format="turtle")
#print(len(g)) # prints 2
file2
=
open
(
r"D:\Text\MyFile2.txt"
,
"w+"
)
RDO_instances
=
Namespace
(
"http://delab.csd.auth.gr/ontologies/2018/RDO-instances#"
)
RBO
=
Namespace
(
"http://delab.csd.auth.gr/ontologies/2018/RBO#"
)
RDO
=
Namespace
(
"http://delab.csd.auth.gr/ontologies/2018/RDO#"
)
LO
=
URIRef
(
"http://delab.csd.auth.gr/ontologies/2018/LO"
)
g
.
load
(
"../Ontologies/Mokos_18_1_7_47.ttl"
,
format
=
"turtle"
)
n
=
"http://delab.csd.auth.gr/ontologies/2018/SAO#System"
for
subj
,
obj
in
g
.
subject_objects
(
predicate
=
RDFS
.
subClassOf
):
##if n in subj:
# print (obj.rsplit('#')[-1])
#else:
lol
=
subj
+
"$"
+
obj
+
"
\n
"
file2
.
write
(
lol
)
# print("{} is a person".format(s))
#for s, p, o in g.triples((None, RDF.type, None)):
# file2.write("{} is a {} \n".format(s, o))
#add unique id
new_req
=
RDO_instances
.
EEMR
#
new_req = RDO_instances.EEMR
#add the S1-S5 or M1-M16 etc
new_req_2
=
RBO
.
M16
new_req_3
=
RBO
.
M17
#
new_req_2 = RBO.M16
#
new_req_3 = RBO.M17
#g.bind('RDO_instances', RDO_instances)
g
.
add
((
new_req
,
RDF
.
type
,
new_req_2
))
g
.
add
((
new_req
,
RDF
.
type
,
new_req_3
))
print
(
g
.
serialize
(
format
=
"turtle"
)
.
decode
(
"utf-8"
))
#
g.add((new_req, RDF.type, new_req_2))
#
g.add((new_req, RDF.type, new_req_3))
#
print(g.serialize(format="turtle").decode("utf-8"))
#save in file
#g.serialize(destination='output.txt', format='turtle')
reqtool/test_scripts/instances.py
0 → 100644
View file @
94573968
from
rdflib
import
Graph
from
rdflib.namespace
import
RDFS
def
get_instances
(
keyword
):
with
open
(
'instances.txt'
)
as
f
:
for
data
in
f
:
if
(
data
.
strip
())
.
endswith
(
keyword
):
spliter_1
=
data
.
split
(
'$'
)
spliter_2
=
spliter_1
[
0
]
.
split
(
"#"
)
print
(
spliter_2
[
len
(
spliter_2
)
-
1
])
file2
=
open
(
r"instances.txt"
,
"w+"
)
g
=
Graph
()
g
.
load
(
"../Ontologies/Mokos_18_1_7_47.ttl"
,
format
=
"turtle"
)
for
subj
,
obj
in
g
.
subject_objects
(
predicate
=
RDFS
.
range
):
subClass
=
subj
+
"$"
+
obj
+
"
\n
"
file2
.
write
(
subClass
)
get_instances
(
"SAO#State"
)
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