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
98d70a8b
Commit
98d70a8b
authored
Mar 28, 2022
by
Thodoris Nestoridis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Get Dictionary in all depths (only back end)
parent
5e989125
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
156 deletions
+55
-156
parse_ontologies.py
...reqman/apps/reqtool/rest_api/services/parse_ontologies.py
+55
-156
No files found.
reqtool/reqman/api/reqman/apps/reqtool/rest_api/services/parse_ontologies.py
View file @
98d70a8b
...
@@ -234,20 +234,29 @@ def get_dmo_instance_and_comment(keyword):
...
@@ -234,20 +234,29 @@ def get_dmo_instance_and_comment(keyword):
#Classes and Comments
#Classes and Comments
def
get_dmo_classes_and_comment
(
keyword
,
g
):
def
get_dmo_classes_and_comment
(
keyword
,
g
):
dmo_dic
=
{}
dic_list
=
[]
dic_list
=
[]
dmo_dic_in
=
{}
dic_list_in
=
[]
dic_list_in
=
[]
dmo_dic_backup
=
{}
dmo_dic_backup
=
{}
dic_list_backup
=
[]
out_list_instance
=
[]
out_list_instance
=
[]
out_list_com
=
[]
keywordspl
=
keyword
.
split
(
"#"
)
keywordspl
=
keyword
.
split
(
"#"
)
section
=
keywordspl
[
len
(
keywordspl
)
-
1
]
section
=
keywordspl
[
len
(
keywordspl
)
-
1
]
in_list
=
[
section
]
in_list
=
[
section
]
for
extra
in
in_list
:
for
extra
in
in_list
:
for
uri
in
list_of_DSO
:
for
uri
in
list_of_DSO
:
per
=
URIRef
(
uri
+
extra
)
per
=
URIRef
(
uri
+
extra
)
dmo_dic_in
=
{}
#get Instance of Upper (System, Function etc.)
for
s
,
p
,
o
in
g
.
triples
((
None
,
RDF
.
type
,
per
)):
spl
=
s
.
split
(
"#"
)
uri
=
spl
[
len
(
spl
)
-
2
]
.
split
(
"/"
)
find_comment_gen_instance
=
""
for
urired2
in
list_of_DSO
:
pop
=
URIRef
(
urired2
+
spl
[
len
(
spl
)
-
1
])
for
q1
,
w1
,
m1
in
g
.
triples
((
pop
,
RDFS
.
comment
,
None
)):
find_comment_gen_instance
=
(
str
(
m1
)
.
replace
(
"
\r
"
,
""
))
.
replace
(
"
\n
"
,
""
)
dmo_dic_in
=
{
'Instance'
:
spl
[
len
(
spl
)
-
1
],
"Comment"
:
find_comment_gen_instance
}
dic_list_in
.
append
(
dmo_dic_in
)
#get Instance of First Subclass
for
s
,
p
,
o
in
g
.
triples
((
None
,
RDFS
.
subClassOf
,
per
)):
for
s
,
p
,
o
in
g
.
triples
((
None
,
RDFS
.
subClassOf
,
per
)):
spl
=
s
.
split
(
"#"
)
spl
=
s
.
split
(
"#"
)
out_list_instance
.
append
(
spl
[
len
(
spl
)
-
1
])
out_list_instance
.
append
(
spl
[
len
(
spl
)
-
1
])
...
@@ -257,6 +266,7 @@ def get_dmo_classes_and_comment(keyword, g):
...
@@ -257,6 +266,7 @@ def get_dmo_classes_and_comment(keyword, g):
Clcomment
=
(
str
(
oas
)
.
replace
(
"
\r
"
,
""
))
.
replace
(
"
\n
"
,
""
)
Clcomment
=
(
str
(
oas
)
.
replace
(
"
\r
"
,
""
))
.
replace
(
"
\n
"
,
""
)
instance_list
=
[]
instance_list
=
[]
instance_dict
=
{}
instance_dict
=
{}
subclass_list
=
[]
for
uri
in
list_of_DSO
:
for
uri
in
list_of_DSO
:
per
=
URIRef
(
uri
+
comment
)
per
=
URIRef
(
uri
+
comment
)
for
s2
,
p2
,
o2
in
g
.
triples
((
None
,
RDF
.
type
,
per
)):
for
s2
,
p2
,
o2
in
g
.
triples
((
None
,
RDF
.
type
,
per
)):
...
@@ -269,37 +279,7 @@ def get_dmo_classes_and_comment(keyword, g):
...
@@ -269,37 +279,7 @@ def get_dmo_classes_and_comment(keyword, g):
#print("Instance", spl[len(spl) - 1], "Comment", find_comment_main_instance)
#print("Instance", spl[len(spl) - 1], "Comment", find_comment_main_instance)
instance_dict
=
{
"Instance"
:
spl
[
len
(
spl
)
-
1
],
"Comment"
:
find_comment_main_instance
}
instance_dict
=
{
"Instance"
:
spl
[
len
(
spl
)
-
1
],
"Comment"
:
find_comment_main_instance
}
instance_list
.
append
(
instance_dict
)
instance_list
.
append
(
instance_dict
)
dmo_dic_backup
=
{
"Class"
:
str
(
comment
),
"Comment"
:
Clcomment
,
'Subclass'
:
''
,
'Instance_of_Class'
:
instance_list
}
for
s1
,
p1
,
o1
in
g
.
triples
((
None
,
RDFS
.
subClassOf
,
per
)):
for
extra
in
in_list
:
for
uri
in
list_of_DSO
:
per
=
URIRef
(
uri
+
extra
)
for
s
,
p
,
o
in
g
.
triples
((
None
,
RDF
.
type
,
per
)):
spl
=
s
.
split
(
"#"
)
uri
=
spl
[
len
(
spl
)
-
2
]
.
split
(
"/"
)
find_comment_gen_instance
=
""
for
urired2
in
list_of_DSO
:
pop
=
URIRef
(
urired2
+
spl
[
len
(
spl
)
-
1
])
for
q1
,
w1
,
m1
in
g
.
triples
((
pop
,
RDFS
.
comment
,
None
)):
find_comment_gen_instance
=
(
str
(
m1
)
.
replace
(
"
\r
"
,
""
))
.
replace
(
"
\n
"
,
""
)
dmo_dic_in
=
{
'Instance'
:
spl
[
len
(
spl
)
-
1
],
"Comment"
:
find_comment_gen_instance
}
dic_list_in
.
append
(
dmo_dic_in
)
for
comment
in
out_list_instance
:
name_class
=
""
comment_class
=
""
for
uri
in
list_of_DSO
:
per
=
URIRef
(
uri
+
comment
)
for
s
,
p
,
o
in
g
.
triples
((
per
,
RDFS
.
comment
,
None
)):
out_list_com
.
append
(
str
(
comment
))
name_class
=
str
(
comment
)
out_list_com
.
append
((
str
(
o
)
.
replace
(
"
\r
"
,
""
))
.
replace
(
"
\n
"
,
""
))
comment_class
=
(
str
(
o
)
.
replace
(
"
\r
"
,
""
))
.
replace
(
"
\n
"
,
""
)
suclass_dict
=
{}
sub_ins_dict
=
{}
subclass_list
=
[]
for
uri
in
list_of_DSO
:
subclas_name
=
""
per2
=
URIRef
(
uri
+
comment
)
for
s1
,
p1
,
o1
in
g
.
triples
((
None
,
RDFS
.
subClassOf
,
per2
)):
spl1
=
s1
.
split
(
"#"
)
spl1
=
s1
.
split
(
"#"
)
#subclass_list.append(spl1[len(spl1) - 1])
#subclass_list.append(spl1[len(spl1) - 1])
subclas_name
=
spl1
[
len
(
spl1
)
-
1
]
subclas_name
=
spl1
[
len
(
spl1
)
-
1
]
...
@@ -320,131 +300,50 @@ def get_dmo_classes_and_comment(keyword, g):
...
@@ -320,131 +300,50 @@ def get_dmo_classes_and_comment(keyword, g):
sub_ins_dict
=
{
"Instance"
:
spl2
[
len
(
spl2
)
-
1
],
"Comment"
:
find_comment_instance
}
sub_ins_dict
=
{
"Instance"
:
spl2
[
len
(
spl2
)
-
1
],
"Comment"
:
find_comment_instance
}
sub_ins
.
append
(
sub_ins_dict
)
sub_ins
.
append
(
sub_ins_dict
)
###############################
###############################
subsuclass_dict
=
{}
#get Instance of all subclasses
subsubclass_list
=
[]
subsubclass_list
=
get_Classes_Dictionary
(
subclas_name
)
for
uris
in
list_of_DSO
:
per2
=
URIRef
(
uris
+
subclas_name
)
for
k1
,
l1
,
h1
in
g
.
triples
((
None
,
RDFS
.
subClassOf
,
per2
)):
spl1
=
k1
.
split
(
"#"
)
subsubclas_name
=
spl1
[
len
(
spl1
)
-
1
]
kop
=
URIRef
(
uri
+
spl1
[
len
(
spl1
)
-
1
])
subfind_comment
=
""
subfind_comment_instance
=
""
for
q
,
w
,
m
in
g
.
triples
((
kop
,
RDFS
.
comment
,
None
)):
subfind_comment
=
(
str
(
m
)
.
replace
(
"
\r
"
,
""
))
.
replace
(
"
\n
"
,
""
)
subsub_ins_dict
=
{}
subsub_ins
=
[]
for
suburired
in
list_of_DSO
:
per3
=
URIRef
(
suburired
+
spl1
[
len
(
spl1
)
-
1
])
for
s2
,
p2
,
o2
in
g
.
triples
((
None
,
RDF
.
type
,
per3
)):
spl2
=
s2
.
split
(
"#"
)
for
urired2
in
list_of_DSO
:
kop2
=
URIRef
(
urired2
+
spl2
[
len
(
spl2
)
-
1
])
for
q1
,
w1
,
m1
in
g
.
triples
((
kop2
,
RDFS
.
comment
,
None
)):
subfind_comment_instance
=
(
str
(
m1
)
.
replace
(
"
\r
"
,
""
))
.
replace
(
"
\n
"
,
""
)
subsub_ins_dict
=
{
"Instance"
:
spl2
[
len
(
spl2
)
-
1
],
"Comment"
:
subfind_comment_instance
}
subsub_ins
.
append
(
subsub_ins_dict
)
#####################################################################
subsub_ins_dict
=
{}
subsubsuclass_dict
=
{}
subsubsubclass_list
=
[]
for
uris
in
list_of_DSO
:
per2
=
URIRef
(
uris
+
subsubclas_name
)
for
k1
,
l1
,
h1
in
g
.
triples
((
None
,
RDFS
.
subClassOf
,
per2
)):
spl1
=
k1
.
split
(
"#"
)
subsubsubclas_name
=
spl1
[
len
(
spl1
)
-
1
]
kop
=
URIRef
(
uri
+
spl1
[
len
(
spl1
)
-
1
])
subsubfind_comment
=
""
subsubfind_comment_instance
=
""
for
q
,
w
,
m
in
g
.
triples
((
kop
,
RDFS
.
comment
,
None
)):
subsubfind_comment
=
(
str
(
m
)
.
replace
(
"
\r
"
,
""
))
.
replace
(
"
\n
"
,
""
)
subsubsub_ins_dict
=
{}
subsubsub_ins
=
[]
for
subsuburired
in
list_of_DSO
:
per3
=
URIRef
(
subsuburired
+
spl1
[
len
(
spl1
)
-
1
])
for
s2
,
p2
,
o2
in
g
.
triples
((
None
,
RDF
.
type
,
per3
)):
spl2
=
s2
.
split
(
"#"
)
for
urired2
in
list_of_DSO
:
kop2
=
URIRef
(
urired2
+
spl2
[
len
(
spl2
)
-
1
])
for
q1
,
w1
,
m1
in
g
.
triples
((
kop2
,
RDFS
.
comment
,
None
)):
subsubfind_comment_instance
=
(
str
(
m1
)
.
replace
(
"
\r
"
,
""
))
.
replace
(
"
\n
"
,
""
)
subsubsub_ins_dict
=
{
"Instance"
:
spl2
[
len
(
spl2
)
-
1
],
"Comment"
:
subsubfind_comment_instance
}
subsubsub_ins
.
append
(
subsubsub_ins_dict
)
#####################################################################
subsubsub_ins_dict
=
{}
subsubsubsuclass_dict
=
{}
subsubsubsubclass_list
=
[]
for
uris
in
list_of_DSO
:
per2
=
URIRef
(
uris
+
subsubsubclas_name
)
for
k1
,
l1
,
h1
in
g
.
triples
((
None
,
RDFS
.
subClassOf
,
per2
)):
spl1
=
k1
.
split
(
"#"
)
subsubsubsubclas_name
=
spl1
[
len
(
spl1
)
-
1
]
kop
=
URIRef
(
uri
+
spl1
[
len
(
spl1
)
-
1
])
subsubsubfind_comment
=
""
subsubsubfind_comment_instance
=
""
for
q
,
w
,
m
in
g
.
triples
((
kop
,
RDFS
.
comment
,
None
)):
subsubsubfind_comment
=
(
str
(
m
)
.
replace
(
"
\r
"
,
""
))
.
replace
(
"
\n
"
,
""
)
subsubsubsub_ins_dict
=
{}
subsubsubsub_ins
=
[]
for
subsubsuburired
in
list_of_DSO
:
per3
=
URIRef
(
subsubsuburired
+
spl1
[
len
(
spl1
)
-
1
])
for
s2
,
p2
,
o2
in
g
.
triples
((
None
,
RDF
.
type
,
per3
)):
spl2
=
s2
.
split
(
"#"
)
for
suburired2
in
list_of_DSO
:
kop2
=
URIRef
(
suburired2
+
spl2
[
len
(
spl2
)
-
1
])
for
q1
,
w1
,
m1
in
g
.
triples
((
kop2
,
RDFS
.
comment
,
None
)):
subsubsubfind_comment_instance
=
(
str
(
m1
)
.
replace
(
"
\r
"
,
""
))
.
replace
(
"
\n
"
,
""
)
subsubsubsub_ins_dict
=
{
"Instance"
:
spl2
[
len
(
spl2
)
-
1
],
"Comment"
:
subsubsubfind_comment_instance
}
subsubsubsub_ins
.
append
(
subsubsubsub_ins_dict
)
subsubsubsuclass_dict
=
{
'SubSubClass_name'
:
subsubsubsubclas_name
,
'SubSubclassComment'
:
subsubsubfind_comment
,
'SubInstanceOfSubclass'
:
subsubsubsub_ins
}
subsubsubsubclass_list
.
append
(
subsubsubsuclass_dict
)
#####################################################################
subsubsuclass_dict
=
{
'SubSubClass_name'
:
subsubsubclas_name
,
'SubSubclassComment'
:
subsubfind_comment
,
'SubInstanceOfSubclass'
:
subsubsub_ins
,
'SubSubClass'
:
subsubsubsubclass_list
}
subsubsubclass_list
.
append
(
subsubsuclass_dict
)
#########################################################################
subsuclass_dict
=
{
'SubSubClass_name'
:
subsubclas_name
,
'SubSubclassComment'
:
subfind_comment
,
'SubInstanceOfSubclass'
:
subsub_ins
,
'SubSubClass'
:
subsubsubclass_list
}
subsubclass_list
.
append
(
subsuclass_dict
)
suclass_dict
=
{
'SubClass_name'
:
subclas_name
,
'SubclassComment'
:
find_comment
,
'InstanceOfSubclass'
:
sub_ins
,
'SubSubClass'
:
subsubclass_list
}
suclass_dict
=
{
'SubClass_name'
:
subclas_name
,
'SubclassComment'
:
find_comment
,
'InstanceOfSubclass'
:
sub_ins
,
'SubSubClass'
:
subsubclass_list
}
subclass_list
.
append
(
suclass_dict
)
subclass_list
.
append
(
suclass_dict
)
############################################
############################################
############################################
dmo_dic_backup
=
{
"Class"
:
str
(
comment
),
"Comment"
:
Clcomment
,
'Subclass'
:
subclass_list
,
'Instance_of_Class'
:
instance_list
}
instance_list
=
[]
dic_list
.
append
(
dmo_dic_backup
)
instance_dict
=
{}
Dictionary_Data
=
{
"Name"
:
section
,
"TheClasses"
:
dic_list
,
"GeneralInstances"
:
dic_list_in
}
for
uri
in
list_of_DSO
:
#print(Dictionary_Data)
per
=
URIRef
(
uri
+
name_class
)
return
Dictionary_Data
for
s2
,
p2
,
o2
in
g
.
triples
((
None
,
RDF
.
type
,
per
)):
spl
=
s2
.
split
(
"#"
)
find_comment_main_instance
=
""
def
get_Classes_Dictionary
(
name
):
for
urired2
in
list_of_DSO
:
#subsubsub_ins_dict = {}
pop
=
URIRef
(
urired2
+
spl
[
len
(
spl
)
-
1
])
subsubsubsuclass_dict
=
{}
for
q1
,
w1
,
m1
in
g
.
triples
((
pop
,
RDFS
.
comment
,
None
)):
subsubsubsubclass_list
=
[]
find_comment_main_instance
=
(
str
(
m1
)
.
replace
(
"
\r
"
,
""
))
.
replace
(
"
\n
"
,
""
)
for
uris
in
list_of_DSO
:
#print("Instance", spl[len(spl) - 1], "Comment", find_comment_main_instance)
per2
=
URIRef
(
uris
+
name
)
instance_dict
=
{
"Instance"
:
spl
[
len
(
spl
)
-
1
],
"Comment"
:
find_comment_main_instance
}
for
k1
,
l1
,
h1
in
g
.
triples
((
None
,
RDFS
.
subClassOf
,
per2
)):
instance_list
.
append
(
instance_dict
)
spl1
=
k1
.
split
(
"#"
)
#######################################################################################
subsubsubsubclas_name
=
spl1
[
len
(
spl1
)
-
1
]
kop
=
URIRef
(
uris
+
spl1
[
len
(
spl1
)
-
1
])
subsubsubfind_comment
=
""
subsubsubfind_comment_instance
=
""
for
q
,
w
,
m
in
g
.
triples
((
kop
,
RDFS
.
comment
,
None
)):
subsubsubfind_comment
=
(
str
(
m
)
.
replace
(
"
\r
"
,
""
))
.
replace
(
"
\n
"
,
""
)
subsubsubsub_ins_dict
=
{}
subsubsubsub_ins
=
[]
for
subsubsuburired
in
list_of_DSO
:
per3
=
URIRef
(
subsubsuburired
+
spl1
[
len
(
spl1
)
-
1
])
for
s2
,
p2
,
o2
in
g
.
triples
((
None
,
RDF
.
type
,
per3
)):
spl2
=
s2
.
split
(
"#"
)
for
suburired2
in
list_of_DSO
:
kop2
=
URIRef
(
suburired2
+
spl2
[
len
(
spl2
)
-
1
])
for
q1
,
w1
,
m1
in
g
.
triples
((
kop2
,
RDFS
.
comment
,
None
)):
subsubsubfind_comment_instance
=
(
str
(
m1
)
.
replace
(
"
\r
"
,
""
))
.
replace
(
"
\n
"
,
""
)
subsubsubsub_ins_dict
=
{
"Instance"
:
spl2
[
len
(
spl2
)
-
1
],
"Comment"
:
subsubsubfind_comment_instance
}
subsubsubsub_ins
.
append
(
subsubsubsub_ins_dict
)
#get current Subclass -Subclasses / Instances
newsubclass_list
=
get_Classes_Dictionary
(
subsubsubsubclas_name
)
subsubsubsuclass_dict
=
{
'SubSubClass_name'
:
subsubsubsubclas_name
,
'SubSubclassComment'
:
subsubsubfind_comment
,
'SubInstanceOfSubclass'
:
subsubsubsub_ins
,
'SubSubClass'
:
newsubclass_list
}
subsubsubsubclass_list
.
append
(
subsubsubsuclass_dict
)
return
subsubsubsubclass_list
dmo_dic
=
{
"Class"
:
name_class
,
"Comment"
:
comment_class
,
'Subclass'
:
subclass_list
,
'Instance_of_Class'
:
instance_list
}
dic_list
.
append
(
dmo_dic
)
if
out_list_com
:
Dictionary_Data
=
{
"Name"
:
section
,
"TheClasses"
:
dic_list
,
"GeneralInstances"
:
dic_list_in
}
#print(Dictionary_Data)
return
Dictionary_Data
#return dic_list
else
:
if
dic_list_backup
:
Dictionary_Data
=
{
"Name"
:
section
,
"TheClasses"
:
dic_list_backup
,
"GeneralInstances"
:
dic_list_in
}
return
Dictionary_Data
#return dic_list_backup
else
:
dmo_dic_backup
=
{
"Class"
:
""
,
"Comment"
:
""
}
dic_list_backup
.
append
(
dmo_dic_backup
)
Dictionary_Data
=
{
"Name"
:
section
,
"TheClasses"
:
dic_list_backup
,
"GeneralInstances"
:
dic_list_in
}
return
Dictionary_Data
#return dic_list_backup
...
...
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