Commit 33b637a4 authored by Thodoris Nestoridis's avatar Thodoris Nestoridis

write the req in Ontology(part 1 completed)

parent c22fcd4e
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
<div class="col"> <div class="col">
<form class="form-group form-inline"> <form class="form-group form-inline">
<mat-form-field class="example-full-width"> <mat-form-field class="example-full-width">
<mat-label>Unit</mat-label> <mat-label>Flow</mat-label>
<input type="text" <input type="text"
placeholder="Pick one" placeholder="Pick one"
aria-label="Number" aria-label="Number"
......
...@@ -12,22 +12,22 @@ find_subclass_domain_range() ...@@ -12,22 +12,22 @@ find_subclass_domain_range()
#import pprint #import pprint
#pprint.pprint(get_main_sytax()) #pprint.pprint(get_main_sytax())
MAIN_CHOICES = ( ("",""), ("M1", "M1 : system/function shall [not] set [<quantifier>] item [to stateValue]"), MAIN_CHOICES = ( ("",""), ("M1", "M1"),
("M2", "M2 : system/function shall [not] set state to stateValue"), ("M2", "M2"),
("M3", "M3 : system/function shall [not] send [<quanti fier>] item"), ("M3", "M3"),
("M4", "M4 : system/function shall [not] receive [<quantifier>] item"), ("M4", "M4"),
("M5", "M5 : system/function shall [not] ingest flow"), ("M5", "M5"),
("M6", "M6 : system/function shall [not] emit flow"), ("M6", "M6"),
("M7", "M7 : system shall [not] perform function"), ("M7", "M7"),
("M8", "M8 : function shall [not] invoke function"), ("M8", "M8"),
("M9", "M9 : system shall [not] present interface [to system]"), ("M9", "M9"),
("M10", "M10 : system/interface shall [not] transfer flow/item"), ("M10", "M10"),
("M11", "M11 : system shall [not] interact with system [using <connection>] [as de ned in <text>]"), ("M11", "M11"),
("M12", "M12 : system shall [not] have state state [with values stateSet]"), ("M12", "M12"),
("M13", "M13 : system state stateValue shall [not] have substate state [with values stateSet]"), ("M13", "M13"),
("M14", "M14 : system item shall [not] take values from stateSet"), ("M14", "M14"),
("M15", "M15 : system item shall [not] be composed from item"), ("M15", "M15"),
("M16", "M16 : system shall [not] contain system") ("M16", "M16"),
) )
#to be updated with domains from DSO #to be updated with domains from DSO
......
...@@ -22,10 +22,10 @@ NUMBER_UNITS_CHOICES = (("",""), ("METERS","METERS"), ("KILOMETERS","KILOMETERS" ...@@ -22,10 +22,10 @@ NUMBER_UNITS_CHOICES = (("",""), ("METERS","METERS"), ("KILOMETERS","KILOMETERS"
TIME_UNITS_CHOICES = (("SECONDS","SECONDS"), ("MINUTES","MINUTES"), ("MILLISECONDS","MILLISECONDS")) TIME_UNITS_CHOICES = (("SECONDS","SECONDS"), ("MINUTES","MINUTES"), ("MILLISECONDS","MILLISECONDS"))
FLOW_CHOICES = get_instances("SAO#Flow") FLOW_CHOICES = get_instances("SAO#Flow")
# FLOW returns () # FLOW returns ()
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"))
S5_6_CHOICES = (("at even intervals","AT EVEN INTERVALS"), ("sequentially","SEQUENTIALLY")) S5_6_CHOICES = (("AT EVEN INTERVALS","AT EVEN INTERVALS"), ("SEQUENTIALLY","SEQUENTIALLY"))
S_CHOICES = NUMERICAL_AFFIRMATIVE_CHOICES + S2_CHOICES + S3_CHOICES + S4_CHOICES + S5_6_CHOICES S_CHOICES = NUMERICAL_AFFIRMATIVE_CHOICES + S2_CHOICES + S3_CHOICES + S4_CHOICES + S5_6_CHOICES
......
...@@ -4,10 +4,16 @@ from rdflib import ConjunctiveGraph, URIRef, RDFS, RDF, Namespace ...@@ -4,10 +4,16 @@ from rdflib import ConjunctiveGraph, URIRef, RDFS, RDF, Namespace
from reqman.apps.reqtool.rest_api.services.parse_ontologies import * from reqman.apps.reqtool.rest_api.services.parse_ontologies import *
from reqman.apps.reqtool.models.main_req import SYSTEM_CHOICES, FUNCTION_CHOICES, INTERFACE_CHOICES, FLOW_CHOICES, ITEM_CHOICES, STATE_CHOICES, STATE_SET_CHOICES from reqman.apps.reqtool.models.main_req import SYSTEM_CHOICES, FUNCTION_CHOICES, INTERFACE_CHOICES, FLOW_CHOICES, ITEM_CHOICES, STATE_CHOICES, STATE_SET_CHOICES
Ontology_file = "../../Ontologies/Mokos_18_1_7_47.ttl"
main_syntax = get_main_sytax() main_syntax = get_main_sytax()
def getclassofmain(main):
return(findclassofmain(main))
def inferencing(boilerlate, prefix, main, suffix):
def inferencing(project, boilerlate, prefix, main, suffix):
listofboil = [] listofboil = []
listofprefix = [] listofprefix = []
listofmain = [] listofmain = []
...@@ -21,25 +27,40 @@ def inferencing(boilerlate, prefix, main, suffix): ...@@ -21,25 +27,40 @@ def inferencing(boilerlate, prefix, main, suffix):
for i in suffix: for i in suffix:
listofsuffix.append(list(i.values())) listofsuffix.append(list(i.values()))
#findclassofmain(listofmain) #findclassofmain(listofmain)
exportboiltottl(listofboil, findclassofmain(listofmain)) exportboiltottl(project, listofprefix, listofboil, listofmain, listofsuffix)
print("inferencing...") #print(project)
#print(listofboil[0][0]['id']) #print(listofboil[0][0]['id'])
#print(listofprefix[0][0]['id']) #print(listofprefix[0][0]['id'])
def exportboiltottl(boilerplate, classofmain): def exportboiltottl(project, prefix, boilerplate, main, suffix):
per_instances = URIRef("http://delab.csd.auth.gr/ontologies/2018/RDO-instances#") per_instances = URIRef("http://delab.csd.auth.gr/ontologies/2018/RDO-instances#")
rdo = URIRef("http://delab.csd.auth.gr/ontologies/2018/RDO#") rdo = URIRef("http://delab.csd.auth.gr/ontologies/2018/RDO#")
rbo = URIRef("http://delab.csd.auth.gr/ontologies/2018/RBO#")
g = Graph() g = Graph()
g.load(Ontology_file, format="turtle")
#for b in boilerplate: #for b in boilerplate:
for i in range(len(boilerplate)): for i in range(len(boilerplate)):
title = boilerplate[i][0]['title'] title = boilerplate[i][0]['title']
#title = BNode() #title = BNode()
g.add((per_instances + title, RDF.type, rdo + 'Requirement')) g.add((per_instances + title, RDF.type, rdo + 'Requirement'))
if (boilerplate[i][0]['has_main'] == True): if (boilerplate[i][0]['has_main'] == True):
g.add((per_instances + title, rdo + 'hasMain', per_instances+(title+"_"+classofmain[i]))) g.add((per_instances + title, rdo + 'hasMain', per_instances+(title+"_"+ main[i][0]['main_choices'])))
if (boilerplate[i][0]['has_prefix'] == True):
g.add((per_instances + title, rdo + 'hasPrefix', per_instances+(title+"_"+ prefix[i][0]['simple_prefix'])))
g.add((per_instances+(title+"_"+ main[i][0]['main_choices']), RDF.type, rbo + main[i][0]['main_choices']))
if main[i][0]['sys_fun_inter'] != "":
#need to know in which file is the SUbject, RDO instances? or RDO-AOCS instance? or somewhere else?
g.add((per_instances+(title+"_"+ main[i][0]['main_choices']), rbo+"isRelatedToSubject", per_instances + main[i][0]['sys_fun_inter']))
if (boilerplate[i][0]['has_suffix'] == True):
g.add((per_instances + title, rdo + 'hasSuffix', per_instances+(title+"_"+ suffix[i][0]['suffix_choices'])))
#if (boilerplate[i][0]['has_prefix'] == True):
# g.add((per_instances+(title+"_"+ main[i][0]['main_choices']), RDF.type, rbo + main[i][0]['main_choices']))
g.serialize(destination='../../Ontologies/'+project+'.ttl', format='turtle')
print(g.serialize(format="turtle").decode("utf-8")) #print(g.serialize(format="turtle").decode("utf-8"))
def findclassofmain(listofmain): def findclassofmain(listofmain):
...@@ -48,61 +69,64 @@ def findclassofmain(listofmain): ...@@ -48,61 +69,64 @@ def findclassofmain(listofmain):
verbsmain = main_syntax[('M'+str(i+1))]['Verbs'] verbsmain = main_syntax[('M'+str(i+1))]['Verbs']
subsmain = main_syntax[('M'+str(i+1))]['Subject'] subsmain = main_syntax[('M'+str(i+1))]['Subject']
attrsmain = main_syntax[('M'+str(i+1))]['Attributes'] attrsmain = main_syntax[('M'+str(i+1))]['Attributes']
for currentmain in range(len(listofmain)): #for currentmain in range(len(listofmain)):
currentverb = listofmain[currentmain][0]['verb'] currentverb = listofmain['verb']
currentsubject = listofmain[currentmain][0]['sys_fun_inter'] currentsubject = listofmain['sys_fun_inter']
currentattr = listofmain[currentmain][0]['sys_fun_inter'] currentattr = listofmain['sys_fun_inter']
for verbmain in verbsmain: for verbmain in verbsmain:
if (verbmain.upper() == currentverb.upper()): flag = 0
for submain in subsmain: if (verbmain.upper() == currentverb.upper()):
flag = 0 for submain in subsmain:
if submain == "System": flag = 0
for sys in SYSTEM_CHOICES: if submain == "System":
if sys[0] == currentsubject: for sys in SYSTEM_CHOICES:
flag = 1 if sys[0] == currentsubject:
break flag = 1
if submain == "Function": break
for sys in FUNCTION_CHOICES: if submain == "Function":
if sys[0] == currentsubject: for sys in FUNCTION_CHOICES:
flag = 1 if sys[0] == currentsubject:
break flag = 1
if submain == "Interface": break
for sys in INTERFACE_CHOICES: if submain == "Interface":
if sys[0] == currentsubject: for sys in INTERFACE_CHOICES:
flag = 1 if sys[0] == currentsubject:
break flag = 1
if flag == 1 : break
for attrmain in attrsmain: if flag == 1 :
if attrmain == "Flow": for attrmain in attrsmain:
for sys in FLOW_CHOICES: if attrmain == "Flow":
if sys[0] == currentattr: for sys in FLOW_CHOICES:
classlist.append('M'+str(i+1)) if sys[0] == currentattr:
break classlist.append('M'+str(i+1))
if attrmain == "Item": return(classlist)
for sys in ITEM_CHOICES: if attrmain == "Item":
if sys[0] == currentattr: for sys in ITEM_CHOICES:
classlist.append('M'+str(i+1)) if sys[0] == currentattr:
break classlist.append('M'+str(i+1))
if attrmain == "Function": return(classlist)
for sys in FUNCTION_CHOICES: if attrmain == "Function":
if sys[0] == currentattr: for sys in FUNCTION_CHOICES:
classlist.append('M'+str(i+1)) if sys[0] == currentattr:
break classlist.append('M'+str(i+1))
if attrmain == "System": return(classlist)
for sys in SYSTEM_CHOICES: if attrmain == "System":
if sys[0] == currentattr: for sys in SYSTEM_CHOICES:
classlist.append('M'+str(i+1)) if sys[0] == currentattr:
break classlist.append('M'+str(i+1))
if attrmain == "Interface": return(classlist)
for sys in INTERFACE_CHOICES: if attrmain == "Interface":
if sys[0] == currentattr: for sys in INTERFACE_CHOICES:
classlist.append('M'+str(i+1)) if sys[0] == currentattr:
break classlist.append('M'+str(i+1))
if attrmain == "State": return(classlist)
for sys in (STATE_CHOICES+ STATE_SET_CHOICES): if attrmain == "State":
if sys[0] == currentattr: for sys in (STATE_CHOICES+ STATE_SET_CHOICES):
classlist.append('M'+str(i+1)) if sys[0] == currentattr:
break classlist.append('M'+str(i+1))
return(classlist)
classlist.append("ERROR")
return classlist return classlist
...@@ -9,7 +9,7 @@ from reqman.apps.reqtool.models.main_req import Main ...@@ -9,7 +9,7 @@ from reqman.apps.reqtool.models.main_req import Main
from reqman.apps.reqtool.rest_api.serializers.main_req import MainSerializer from reqman.apps.reqtool.rest_api.serializers.main_req import MainSerializer
from reqman.apps.permissions import IsOwnerOrReadOnly from reqman.apps.permissions import IsOwnerOrReadOnly
from reqman.apps.reqtool.rest_api.services import fuseki from reqman.apps.reqtool.rest_api.services import fuseki, inference
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.views import APIView from rest_framework.views import APIView
...@@ -19,6 +19,9 @@ from reqman.apps.reqtool.models.main_req import STATE_VALUE_CHOICES, SHALL_CHOIC ...@@ -19,6 +19,9 @@ from reqman.apps.reqtool.models.main_req import STATE_VALUE_CHOICES, SHALL_CHOIC
from reqman.apps.reqtool.models.main_req import FLOW_CHOICES, CONNECTION_CHOICES, STATE_SET_CHOICES from reqman.apps.reqtool.models.main_req import FLOW_CHOICES, CONNECTION_CHOICES, STATE_SET_CHOICES
from reqman.apps.reqtool.models.requirements import BoilerplateData from reqman.apps.reqtool.models.requirements import BoilerplateData
from rest_framework.exceptions import APIException
class MainListAPIView(ListAPIView): class MainListAPIView(ListAPIView):
""" """
...@@ -62,11 +65,14 @@ class MainDetailsAPIView(RetrieveUpdateDestroyAPIView): ...@@ -62,11 +65,14 @@ class MainDetailsAPIView(RetrieveUpdateDestroyAPIView):
#add data in thn Model BoilerplateData #add data in thn Model BoilerplateData
mn = (instance['sys_fun_inter'] + ' ' + instance['shall'] + ' ' + instance['verb'] + ' ' + instance['flow_function_interface_item_system_state_stateset']) mn = (instance['sys_fun_inter'] + ' ' + instance['shall'] + ' ' + instance['verb'] + ' ' + instance['flow_function_interface_item_system_state_stateset'])
BoilerplateData.objects.filter(owner_data=instance['boilerplate_of_main'].owner, boilerplate_data_id = instance['boilerplate_of_main']).update(main_data = mn ) BoilerplateData.objects.filter(owner_data=instance['boilerplate_of_main'].owner, boilerplate_data_id = instance['boilerplate_of_main']).update(main_data = mn )
serializer.save() curmain_choices = inference.getclassofmain(instance)
#print(self.new.changed_data) #instance['main_choices'] = curmain_choices[0]
#instance = serializer.save() if curmain_choices[0] == 'ERROR':
#write_fuseki = fuseki.FusekiActions() raise APIException("Main choices not in [M1-M16]")
#write_fuseki.write(serializer.data) else:
instance = serializer.save(main_choices = curmain_choices[0])
#Custom actions when DELETE #Custom actions when DELETE
def perform_destroy(self, instance): def perform_destroy(self, instance):
......
...@@ -229,6 +229,7 @@ class InferDetailsAPIView(RetrieveUpdateDestroyAPIView): ...@@ -229,6 +229,7 @@ class InferDetailsAPIView(RetrieveUpdateDestroyAPIView):
#Custom actions when PUT #Custom actions when PUT
def perform_update(self, serializer): def perform_update(self, serializer):
instance = serializer.validated_data instance = serializer.validated_data
project_title = ""
boildata= [] boildata= []
prefixdata = [] prefixdata = []
maindata = [] maindata = []
...@@ -236,13 +237,14 @@ class InferDetailsAPIView(RetrieveUpdateDestroyAPIView): ...@@ -236,13 +237,14 @@ class InferDetailsAPIView(RetrieveUpdateDestroyAPIView):
#pr = (instance['prefix'] + ' ' + instance['system_fun_item'] + ' ' + instance['state_or_verb'] + ' ' + instance['item_function_flow_statevalue']) #pr = (instance['prefix'] + ' ' + instance['system_fun_item'] + ' ' + instance['state_or_verb'] + ' ' + instance['item_function_flow_statevalue'])
#BoilerplateData.objects.filter(owner_data=instance['prefix_boilerplate'].owner, boilerplate_data_id = instance['prefix_boilerplate']). #BoilerplateData.objects.filter(owner_data=instance['prefix_boilerplate'].owner, boilerplate_data_id = instance['prefix_boilerplate']).
#print(instance['infer_group_of_boilerplate'].id) #print(instance['infer_group_of_boilerplate'].id)
project_title = instance['infer_group_of_boilerplate'].title_bgroup
prefix = BoilerplateData.objects.filter(group_of_boilerplate_data = instance['infer_group_of_boilerplate'].id) prefix = BoilerplateData.objects.filter(group_of_boilerplate_data = instance['infer_group_of_boilerplate'].id)
for id in prefix: for id in prefix:
boildata.append(self.getboildata(id.boilerplate_data_id.id)) boildata.append(self.getboildata(id.boilerplate_data_id.id))
prefixdata.append(self.getprefixdata(id.boilerplate_data_id.id)) prefixdata.append(self.getprefixdata(id.boilerplate_data_id.id))
maindata.append(self.getmaindata(id.boilerplate_data_id.id)) maindata.append(self.getmaindata(id.boilerplate_data_id.id))
suffixdata.append(self.getsuffixdata(id.boilerplate_data_id.id)) suffixdata.append(self.getsuffixdata(id.boilerplate_data_id.id))
inference.inferencing(boildata, prefixdata, maindata, suffixdata) inference.inferencing(project_title, boildata, prefixdata, maindata, suffixdata)
#print(prefix[0].boilerplate_data_id.id) #print(prefix[0].boilerplate_data_id.id)
#inference.inferencing(prefix) #inference.inferencing(prefix)
instance.update(inference_data = "aaaoooaaa" ) instance.update(inference_data = "aaaoooaaa" )
......
...@@ -15,6 +15,7 @@ from rest_framework.response import Response ...@@ -15,6 +15,7 @@ from rest_framework.response import Response
from rest_framework.views import APIView from rest_framework.views import APIView
from reqman.apps.reqtool.models.suffix_req import S_CHOICES, NUMBER_UNITS_CHOICES, TIME_UNITS_CHOICES, FLOW_CHOICES from reqman.apps.reqtool.models.suffix_req import S_CHOICES, NUMBER_UNITS_CHOICES, TIME_UNITS_CHOICES, FLOW_CHOICES
from reqman.apps.reqtool.models.suffix_req import NUMERICAL_AFFIRMATIVE_CHOICES, S2_CHOICES, S3_CHOICES, S4_CHOICES, S5_6_CHOICES
from reqman.apps.reqtool.models.requirements import BoilerplateData from reqman.apps.reqtool.models.requirements import BoilerplateData
...@@ -60,7 +61,8 @@ class SuffixDetailsAPIView(RetrieveUpdateDestroyAPIView): ...@@ -60,7 +61,8 @@ class SuffixDetailsAPIView(RetrieveUpdateDestroyAPIView):
#add data in thn Model BoilerplateData #add data in thn Model BoilerplateData
sf = (instance['s_choices'] + ' ' + str(instance['numerical']) + ' ' + instance['mumerical_units'] + ' ' + instance['flow']) sf = (instance['s_choices'] + ' ' + str(instance['numerical']) + ' ' + instance['mumerical_units'] + ' ' + instance['flow'])
BoilerplateData.objects.filter(owner_data=instance['boilerplate_of_suffix'].owner, boilerplate_data_id = instance['boilerplate_of_suffix']).update(suffix_data = sf ) BoilerplateData.objects.filter(owner_data=instance['boilerplate_of_suffix'].owner, boilerplate_data_id = instance['boilerplate_of_suffix']).update(suffix_data = sf )
serializer.save() ssuffix_choice = self.getclassofsuffix(instance["s_choices"])
serializer.save(suffix_choices = ssuffix_choice)
#print(self.new.changed_data) #print(self.new.changed_data)
#instance = serializer.save() #instance = serializer.save()
#write_fuseki = fuseki.FusekiActions() #write_fuseki = fuseki.FusekiActions()
...@@ -72,6 +74,25 @@ class SuffixDetailsAPIView(RetrieveUpdateDestroyAPIView): ...@@ -72,6 +74,25 @@ class SuffixDetailsAPIView(RetrieveUpdateDestroyAPIView):
#add data in thn Model BoilerplateData #add data in thn Model BoilerplateData
#print("deleted") #print("deleted")
instance.delete() instance.delete()
def getclassofsuffix(self, suffix):
for sys in NUMERICAL_AFFIRMATIVE_CHOICES:
if sys[0] == suffix:
return ("S1")
for sys in S2_CHOICES:
if sys[0] == suffix:
return ("S2")
for sys in S3_CHOICES:
if sys[0] == suffix:
return ("S3")
for sys in S4_CHOICES:
if sys[0] == suffix:
return ("S4")
#special case only one option for S5, S6
if S5_6_CHOICES[0][0] == suffix:
return ("S5")
if S5_6_CHOICES[1][0] == suffix:
return ("S6")
class SuffixChoicesViewSet(APIView): class SuffixChoicesViewSet(APIView):
......
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