Commit bf1b8fb5 authored by Thodoris Nestoridis's avatar Thodoris Nestoridis

export data from Ontology file

parent f2622a8f
...@@ -32,4 +32,33 @@ SAO:belongsTo a owl:InverseFunctionalProperty ; ...@@ -32,4 +32,33 @@ SAO:belongsTo a owl:InverseFunctionalProperty ;
rdfs:range SAO:StateSet . rdfs:range SAO:StateSet .
DSO-AOCS-instances:Enable_Disable_State DSO-AOCS-instances:Enable_Disable_State
a SAO:StateSet . a SAO:StateSet .
\ No newline at end of file
RMO:belongsTo a owl:ObjectProperty ;
rdfs:domain RMO:State ;
rdfs:range RMO:StateSet .
RMO:contains a owl:ObjectProperty ;
rdfs:domain RMO:Function ;
rdfs:range RMO:Function .
RMO:generates a owl:ObjectProperty ;
rdfs:domain RMO:Function ;
rdfs:range RMO:Flow .
RMO:invokes a owl:ObjectProperty ;
rdfs:domain RMO:Function ;
rdfs:range RMO:Function .
RMO:performs a owl:ObjectProperty ;
rdfs:domain RMO:System ;
rdfs:range RMO:Function .
RMO:sets a owl:ObjectProperty ;
rdfs:domain RMO:Flow ;
rdfs:range RMO:State .
:mode
rdf:type SAO:State ;
SAO:hasSubState :submode ;
SAO:takesValuesFrom :aocs_modes ;
\ No newline at end of file
This diff is collapsed.
...@@ -27,20 +27,27 @@ MAIN_CHOICES = ( ("",""), ("M1", "M1 : system/function shall [not] set [<quant ...@@ -27,20 +27,27 @@ MAIN_CHOICES = ( ("",""), ("M1", "M1 : system/function shall [not] set [<quant
#to be updated with domains from DSO #to be updated with domains from DSO
#SYSTEM_CHOICES = (("SYSTEM", "SYSTEM"), ("SYSTEM2", "SYSTEM2")) #SYSTEM_CHOICES = (("SYSTEM", "SYSTEM"), ("SYSTEM2", "SYSTEM2"))
SYSTEM_CHOICES = find_extra_keywords("SAO:System") SYSTEM_CHOICES = find_extra_keywords("SAO:System", 1)
FUNCTION_CHOICES = (("FUNCTION", "FUNCTION"), ("FUNCTION2", "FUNCTION2")) #FUNCTION_CHOICES = (("FUNCTION", "FUNCTION"), ("FUNCTION2", "FUNCTION2"))
FUNCTION_CHOICES = find_extra_keywords(":Function", 1) + find_extra_keywords(":Function", 2)
SHALL_CHOICES = ( ("shall", "SHALL"), ("shall not", "SHALL NOT")) SHALL_CHOICES = ( ("shall", "SHALL"), ("shall not", "SHALL NOT"))
QUANTIFIER_CHOICES = ( ("none","NONE"), ("all", "ALL"), ("only", "ONLY"), QUANTIFIER_CHOICES = ( ("none","NONE"), ("all", "ALL"), ("only", "ONLY"),
("more than", "MORE THAN"), ("less than", "LESS THAN"), ("exactly","EXACTLY"), ("more than", "MORE THAN"), ("less than", "LESS THAN"), ("exactly","EXACTLY"),
("at least", "AT LEAST"), ("at most", "AT MOST") ("at least", "AT LEAST"), ("at most", "AT MOST")
) )
NUMBER_UNITS_CHOICES = (("",""), ("meters","METERS"), ("kilometers","KILOMETERS"), ("volt","VOLT")) NUMBER_UNITS_CHOICES = (("",""), ("meters","METERS"), ("kilometers","KILOMETERS"), ("volt","VOLT"))
ITEM_CHOICES = (("ITEM", "ITEM"), ("ITEM2", "ITEM2") ) #ITEM_CHOICES = (("ITEM", "ITEM"), ("ITEM2", "ITEM2") )
STATE_CHOICES = (("state", "STATE"), ("state2", "STATE2")) ITEM_CHOICES = find_extra_keywords("SAO:Item", 1)
STATE_VALUE_CHOICES = (("enabled", "ENABLED"), ("disabled", "DISABLED")) #STATE_VALUE_CHOICES = (("enabled", "ENABLED"), ("disabled", "DISABLED"))
FLOW_CHOICES = (("flow","FLOW"), ("flow2","FLOW2")) STATE_VALUE_CHOICES =find_extra_keywords(":StateValue", 2)
INTERFACE_CHOICES = (("interface","INTERFACE"), ("interface2","INTERFACE2")) #STATE_CHOICES = (("state", "STATE"), ("state2", "STATE2"))
CONNECTION_CHOICES = (("connection","CONNECTION"), ("connection2","CONNECTION2")) STATE_CHOICES = [ 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)
SYSTEM_INTERFACE_CHOICES = SYSTEM_CHOICES + INTERFACE_CHOICES SYSTEM_INTERFACE_CHOICES = SYSTEM_CHOICES + INTERFACE_CHOICES
FLOW_ITEM_CHOICES = FLOW_CHOICES + ITEM_CHOICES FLOW_ITEM_CHOICES = FLOW_CHOICES + ITEM_CHOICES
SYSTEM_OR_FUNCTION_CHOICES = SYSTEM_CHOICES + FUNCTION_CHOICES SYSTEM_OR_FUNCTION_CHOICES = SYSTEM_CHOICES + FUNCTION_CHOICES
...@@ -384,7 +391,7 @@ class Main_M2(models.Model): ...@@ -384,7 +391,7 @@ class Main_M2(models.Model):
main_owner_of_m2 = models.ForeignKey(Main, related_name='main_owner_of_M2', on_delete=models.CASCADE) main_owner_of_m2 = models.ForeignKey(Main, related_name='main_owner_of_M2', on_delete=models.CASCADE)
sys_fun_m2 = models.CharField(choices=SYSTEM_OR_FUNCTION_CHOICES, max_length=100) sys_fun_m2 = models.CharField(choices=SYSTEM_OR_FUNCTION_CHOICES, max_length=100)
shall_m2 = models.CharField(choices=SHALL_CHOICES, max_length=100) shall_m2 = models.CharField(choices=SHALL_CHOICES, max_length=100)
state_m2 = models.CharField(default = ' ', max_length=100) state_m2 = models.CharField(choices = STATE_CHOICES, max_length=100)
statevalue_m2 = models.CharField(choices=STATE_VALUE_CHOICES, max_length=100) statevalue_m2 = models.CharField(choices=STATE_VALUE_CHOICES, max_length=100)
......
...@@ -4,6 +4,9 @@ from reqman.apps.account.models import User ...@@ -4,6 +4,9 @@ from reqman.apps.account.models import User
from pygments.formatters.html import HtmlFormatter from pygments.formatters.html import HtmlFormatter
from pygments import highlight from pygments import highlight
from reqman.apps.reqtool.rest_api.services.parse_ontologies import *
SUFFIX_CHOICES = (("",""), ('S1', 'S1: <numerical-armative> j <closed-interval> [per <time-unit>]'), SUFFIX_CHOICES = (("",""), ('S1', 'S1: <numerical-armative> j <closed-interval> [per <time-unit>]'),
('S2', 'S2: after/before flow'), ('S2', 'S2: after/before flow'),
('S3', 'S3: [every/for a period of/within/for at least] <number> <time-unit> [from flow]'), ('S3', 'S3: [every/for a period of/within/for at least] <number> <time-unit> [from flow]'),
...@@ -15,7 +18,8 @@ NUMERICAL_AFFIRMATIVE_CHOICES = (("", ""), ("more than", "MORE THAN"), ("less th ...@@ -15,7 +18,8 @@ NUMERICAL_AFFIRMATIVE_CHOICES = (("", ""), ("more than", "MORE THAN"), ("less th
("at least", "AT LEAST"), ("at most", "AT MOST")) ("at least", "AT LEAST"), ("at most", "AT MOST"))
NUMBER_UNITS_CHOICES = (("",""), ("meters","METERS"), ("kilometers","KILOMETERS"), ("volt","VOLT")) NUMBER_UNITS_CHOICES = (("",""), ("meters","METERS"), ("kilometers","KILOMETERS"), ("volt","VOLT"))
TIME_UNITS_CHOICES = (("",""), ("seconds","SECONDS"), ("minutes","MINUTES"), ("milliseconds","MILLISECONDS")) TIME_UNITS_CHOICES = (("",""), ("seconds","SECONDS"), ("minutes","MINUTES"), ("milliseconds","MILLISECONDS"))
FLOW_CHOICES = (("flow","FLOW"), ("flow2","FLOW2")) #FLOW_CHOICES = (("flow","FLOW"), ("flow2","FLOW2"))
FLOW_CHOICES = find_extra_keywords(":Flow", 3)
S2_CHOICES = (("before","BEFORE"), ("after","AFTER")) 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")) 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")) S4_CHOICES = (("at the beginning","AT THE BEGINNING"), ("at the end","AT THE END"))
......
IS_SAO_SYSTEM = "SAO:System" #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"
list_of_DSO = ["DSO", "DSO-AOCS", "DSO-AOCS-instances"] list_of_DSO = ["DSO", "DSO-AOCS", "DSO-AOCS-instances"]
list_of_RMO = ["RMO", "RMO-instances", "DSO-AOCS-instances"]
'''Return the Systems from the Ontologies''' '''Return the Systems and Items from the Ontologies'''
def get_keyword(keyword): def get_keyword(keyword):
system_list = [] system_list = []
with open("../../Ontologies/Mokos_18_1_7_47.ttl") as f: for dso in list_of_DSO :
for dso in list_of_DSO : flag_1, flag_2 = 0, 0
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)
'''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: for line in f:
if line.startswith(dso): if line.startswith(dso):
spliter_1 = line.split(':') spliter_1 = line.split(':')
...@@ -17,34 +52,53 @@ def get_keyword(keyword): ...@@ -17,34 +52,53 @@ def get_keyword(keyword):
flag_1 = 1 flag_1 = 1
if flag_1 == 1: if flag_1 == 1:
if ':' in keyword: if ':' in keyword:
if keyword in line and "subClassOf" in line: 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 flag_2 = 1
elif not ':' in keyword: elif not ':' in keyword:
keyword = ':'+keyword keyword = ':'+keyword
if keyword in line and "subClassOf" in line: 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 flag_2 = 1
if flag_1 == 1 and flag_2 == 1: if flag_1 == 1 and flag_2 == 1:
if (line.strip()).endswith('.'): if (line.strip()).endswith('.'):
if not key in system_list: if not key in system_list:
system_list.append(key) system_list.append(key)
flag_1, flag_2 = 0, 0 flag_1, flag_2 = 0, 0
if (line.strip()).endswith('.') and not ((line.strip()).startswith('-') or (line.strip()).startswith('rdfs:comment')) : if (line.strip()).endswith('.') and not ((line.strip()).startswith('-') or ( ':comment' in line)) :
flag_1, flag_2 = 0, 0 flag_1, flag_2 = 0, 0
return system_list return system_list #tuple((str(n), str(n)) for n in system_list)
def find_extra_keywords(keyword):
first_search = get_keyword(keyword) def find_extra_keywords(keyword, choice):
second_search = first_search.copy() third_search = []
for i in first_search: if choice == 1 :
k = get_keyword(i) first_search = get_keyword(keyword)
for kl in k: second_search = first_search.copy()
if not kl in second_search: for i in first_search:
second_search.append(kl) k = get_keyword(i)
third_search = second_search.copy() for kl in k:
for i in second_search: if not kl in second_search:
k = get_keyword(i) second_search.append(kl)
for kl in k: third_search = second_search.copy()
if not kl in third_search: for i in second_search:
third_search.append(kl) k = get_keyword(i)
return tuple((str(n), str(n)) for n in third_search) for kl in k:
\ No newline at end of file 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)
IS_SAO_SYSTEM = ":Interface" IS_SAO_SYSTEM = ":Flow"
list_of_DSO = ["DSO", "DSO-AOCS", "DSO-AOCS-instances"] list_of_DSO = ["DSO", "DSO-AOCS", "DSO-AOCS-instances"]
list_of_RMO = ["RMO", "RMO-instances", "DSO-AOCS-instances", "SAO"]
'''Return the Systems from the Ontologies''' '''Return the Systems and Items from the Ontologies'''
def get_keyword(keyword): def get_keyword(keyword):
system_list = [] system_list = []
with open("../Ontologies/Mokos_18_1_7_47.ttl") as f: for dso in list_of_DSO :
for dso in list_of_DSO : flag_1, flag_2 = 0, 0
flag_1, flag_2 = 0, 0 with open("../Ontologies/Mokos_18_1_7_47.ttl") 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 (line.strip()).startswith(':comment')) :
flag_1, flag_2 = 0, 0
return system_list #tuple((str(n), str(n)) for n in system_list)
'''Return the Flow, from the Ontologies'''
def get_keyword_2(keyword):
system_list = []
for dso in list_of_RMO :
flag_1, flag_2 = 0, 0
with open("../Ontologies/Mokos_18_1_7_47.ttl") as f:
for line in f: for line in f:
if line.startswith(dso): if line.startswith(dso):
spliter_1 = line.split(':') spliter_1 = line.split(':')
...@@ -17,43 +48,68 @@ def get_keyword(keyword): ...@@ -17,43 +48,68 @@ def get_keyword(keyword):
flag_1 = 1 flag_1 = 1
if flag_1 == 1: if flag_1 == 1:
if ':' in keyword: if ':' in keyword:
if keyword in line and "subClassOf" in line: 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 flag_2 = 1
elif not ':' in keyword: elif not ':' in keyword:
keyword = ':'+keyword keyword = ':'+keyword
if keyword in line and "subClassOf" in line: 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 flag_2 = 1
if flag_1 == 1 and flag_2 == 1: if flag_1 == 1 and flag_2 == 1:
if (line.strip()).endswith('.'): if (line.strip()).endswith('.'):
if not key in system_list: if not key in system_list:
system_list.append(key) system_list.append(key)
flag_1, flag_2 = 0, 0 flag_1, flag_2 = 0, 0
if (line.strip()).endswith('.') and not ((line.strip()).startswith('-') or (line.strip()).startswith('rdfs:comment')) : if (line.strip()).endswith('.') and not ((line.strip()).startswith('-') or (line.strip()).startswith(':comment')) :
flag_1, flag_2 = 0, 0 flag_1, flag_2 = 0, 0
return system_list #tuple((str(n), str(n)) for n in system_list) return system_list #tuple((str(n), str(n)) for n in system_list)
def find_extra_keywords(keyword):
first_search = get_keyword(keyword) def find_extra_keywords(keyword, choice):
second_search = first_search.copy() third_search = []
for i in first_search: if choice == 1 :
k = get_keyword(i) first_search = get_keyword(keyword)
print(i) second_search = first_search.copy()
print(k) for i in first_search:
for kl in k: k = get_keyword(i)
if not kl in second_search: #print(i)
second_search.append(kl) #print(k)
third_search = second_search.copy() for kl in k:
for i in second_search: if not kl in second_search:
k = get_keyword(i) second_search.append(kl)
print(i) third_search = second_search.copy()
print(k) for i in second_search:
for kl in k: k = get_keyword(i)
if not kl in third_search: #print(i)
third_search.append(kl) #print(k)
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)
#print(i)
#print(k)
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)
#print(i)
#print(k)
for kl in k:
if not kl in third_search:
third_search.append(kl)
return tuple((str(n), str(n)) for n in third_search) return tuple((str(n), str(n)) for n in third_search)
print(find_extra_keywords(IS_SAO_SYSTEM))
print(get_keyword(IS_SAO_SYSTEM)) #print(len(find_extra_keywords(IS_SAO_SYSTEM, 2)))
\ No newline at end of file STATE_VALUE_CHOICES = find_extra_keywords(":StateValue", 2)
new = [ x for x in find_extra_keywords(":State", 2) if x not in STATE_VALUE_CHOICES ]
print("this is",new)
#print(get_keyword_2(IS_SAO_SYSTEM))
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment