Commit 94573968 authored by Thodoris Nestoridis's avatar Thodoris Nestoridis

new method for parse instances in Ontology file + changes in Prefix

parent 8aecd007
This diff is collapsed.
...@@ -6,6 +6,7 @@ from pygments import highlight ...@@ -6,6 +6,7 @@ from pygments import highlight
from reqman.apps.reqtool.rest_api.services.parse_ontologies import * from reqman.apps.reqtool.rest_api.services.parse_ontologies import *
findsubclass()
MAIN_CHOICES = ( ("",""), ("M1", "M1 : system/function shall [not] set [<quantifier>] item [to stateValue]"), MAIN_CHOICES = ( ("",""), ("M1", "M1 : system/function shall [not] set [<quantifier>] item [to stateValue]"),
("M2", "M2 : system/function shall [not] set state 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 ...@@ -26,28 +27,20 @@ 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 = get_instances("SAO#System")
SYSTEM_CHOICES = find_extra_keywords("SAO:System", 1) FUNCTION_CHOICES = get_instances("SAO#Function")
#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 = get_instances("SAO#Item")
ITEM_CHOICES = find_extra_keywords("SAO:Item", 1) STATE_VALUE_CHOICES =get_instances("SAO#StateValue")
#STATE_VALUE_CHOICES = (("enabled", "ENABLED"), ("disabled", "DISABLED")) STATE_CHOICES = get_instances("SAO#State")#tuple( [ x for x in find_extra_keywords(":State", 2) if x not in STATE_VALUE_CHOICES ])
STATE_VALUE_CHOICES =find_extra_keywords(":StateValue", 2) FLOW_CHOICES = get_instances("SAO#Flow")
#STATE_CHOICES = (("state", "STATE"), ("state2", "STATE2")) INTERFACE_CHOICES = get_instances("SAO#Interface")
STATE_CHOICES = tuple( [ x for x in find_extra_keywords(":State", 2) if x not in STATE_VALUE_CHOICES ]) CONNECTION_CHOICES = get_instances("SAO#Connection")
#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)
VERB_CHOICES = (("set","set"),("send","send"),("receive","receive"),("ingest","ingest"),("emit","emit"),("perform","perform"),("invoke","invoke"), 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"), ("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")) ("take values from","take values from"),("be composed","be composed"),("contain","contain"))
......
from django.db import models from django.db import models
#from reqman.apps.common.models import CoreModel #from reqman.apps.common.models import CoreModel
from reqman.apps.account.models import User 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 reqman.apps.reqtool.models.suffix_req import create_suffix
from pygments.formatters.html import HtmlFormatter from pygments.formatters.html import HtmlFormatter
...@@ -93,16 +93,16 @@ class Prefix(models.Model): ...@@ -93,16 +93,16 @@ class Prefix(models.Model):
prefix_boilerplate = models.ForeignKey(Boilerplate, related_name='prefix_boilerplate', on_delete=models.CASCADE) prefix_boilerplate = models.ForeignKey(Boilerplate, related_name='prefix_boilerplate', on_delete=models.CASCADE)
prefix = models.CharField(choices=PREFIX_CHOICES, max_length=100) prefix = models.CharField(choices=PREFIX_CHOICES, max_length=100)
#state value constraint #state value constraint
item_log = models.TextField(max_length=100, blank=True) system_fun_item = models.CharField(choices= (ITEM_CHOICES + SYSTEM_OR_FUNCTION_CHOICES), max_length=100, blank=True)
system_state = models.TextField(max_length=100, blank=True) state_or_verb = models.CharField(choices=STATE_CHOICES + VERB_CHOICES, max_length=100, blank=True)
state_value = models.TextField(max_length=100, blank=True) #state_value = models.CharField(choices=STATE_VALUE_CHOICES, max_length=100, blank=True)
#occuring functionality #occuring functionality
sys_fun = models.CharField(choices=SYSTEM_OR_FUNCTION_CHOICES, 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) #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) item_function_flow_statevalue = models.CharField(choices=ITEM_FLOW_FUNCTION + STATE_VALUE_CHOICES, max_length=100, blank=True)
#Prefix value P1/P2/P3 #Prefix value P1/P2/P3
logical_expression = models.CharField(choices=LOGICAL_EXPRESSION, max_length=100, blank=True) 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) logic_connective = models.CharField(choices=LOGIC_CONNECTIVE, default='', max_length=100, blank=True)
simple_prefix = models.CharField(choices=SIMPLE_PREFIX_CHOICES, max_length=100) simple_prefix = models.CharField(choices=SIMPLE_PREFIX_CHOICES, max_length=100)
......
...@@ -20,8 +20,7 @@ NUMERICAL_AFFIRMATIVE_CHOICES = (("more than", "MORE THAN"), ("less than", "LESS ...@@ -20,8 +20,7 @@ NUMERICAL_AFFIRMATIVE_CHOICES = (("more than", "MORE THAN"), ("less than", "LESS
("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 = get_instances("SAO#Flow")
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"))
......
from rdflib import Graph
from rdflib.namespace import RDFS
#from subprocess import call #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) #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"] ...@@ -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"] 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)
from rdflib import Graph from rdflib import Graph
from rdflib import Namespace from rdflib import Namespace
from rdflib.namespace import RDF from rdflib.namespace import RDF
from rdflib import ConjunctiveGraph, URIRef
from rdflib.namespace import RDFS
g = Graph() g = Graph()
#g.parse("../Ontologies/Mokos_18_1_7_47 copy.ttl", format="turtle") #g.parse("../Ontologies/Mokos_18_1_7_47 copy.ttl", format="turtle")
#print(len(g)) # prints 2 #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#") RDO_instances = Namespace("http://delab.csd.auth.gr/ontologies/2018/RDO-instances#")
RBO = Namespace("http://delab.csd.auth.gr/ontologies/2018/RBO#") RBO = Namespace("http://delab.csd.auth.gr/ontologies/2018/RBO#")
RDO = Namespace("http://delab.csd.auth.gr/ontologies/2018/RDO#") 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 #add unique id
new_req = RDO_instances.EEMR #new_req = RDO_instances.EEMR
#add the S1-S5 or M1-M16 etc #add the S1-S5 or M1-M16 etc
new_req_2 = RBO.M16 #new_req_2 = RBO.M16
new_req_3 = RBO.M17 #new_req_3 = RBO.M17
#g.bind('RDO_instances', RDO_instances) #g.bind('RDO_instances', RDO_instances)
g.add((new_req, RDF.type, new_req_2)) #g.add((new_req, RDF.type, new_req_2))
g.add((new_req, RDF.type, new_req_3)) #g.add((new_req, RDF.type, new_req_3))
print(g.serialize(format="turtle").decode("utf-8")) #print(g.serialize(format="turtle").decode("utf-8"))
#save in file #save in file
#g.serialize(destination='output.txt', format='turtle') #g.serialize(destination='output.txt', format='turtle')
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")
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