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

write the req in Ontology(part 1 completed)

parent c22fcd4e
......@@ -48,7 +48,7 @@
<div class="col">
<form class="form-group form-inline">
<mat-form-field class="example-full-width">
<mat-label>Unit</mat-label>
<mat-label>Flow</mat-label>
<input type="text"
placeholder="Pick one"
aria-label="Number"
......
......@@ -12,22 +12,22 @@ find_subclass_domain_range()
#import pprint
#pprint.pprint(get_main_sytax())
MAIN_CHOICES = ( ("",""), ("M1", "M1 : system/function shall [not] set [<quantifier>] item [to stateValue]"),
("M2", "M2 : system/function shall [not] set state to stateValue"),
("M3", "M3 : system/function shall [not] send [<quanti fier>] item"),
("M4", "M4 : system/function shall [not] receive [<quantifier>] item"),
("M5", "M5 : system/function shall [not] ingest flow"),
("M6", "M6 : system/function shall [not] emit flow"),
("M7", "M7 : system shall [not] perform function"),
("M8", "M8 : function shall [not] invoke function"),
("M9", "M9 : system shall [not] present interface [to system]"),
("M10", "M10 : system/interface shall [not] transfer flow/item"),
("M11", "M11 : system shall [not] interact with system [using <connection>] [as de ned in <text>]"),
("M12", "M12 : system shall [not] have state state [with values stateSet]"),
("M13", "M13 : system state stateValue shall [not] have substate state [with values stateSet]"),
("M14", "M14 : system item shall [not] take values from stateSet"),
("M15", "M15 : system item shall [not] be composed from item"),
("M16", "M16 : system shall [not] contain system")
MAIN_CHOICES = ( ("",""), ("M1", "M1"),
("M2", "M2"),
("M3", "M3"),
("M4", "M4"),
("M5", "M5"),
("M6", "M6"),
("M7", "M7"),
("M8", "M8"),
("M9", "M9"),
("M10", "M10"),
("M11", "M11"),
("M12", "M12"),
("M13", "M13"),
("M14", "M14"),
("M15", "M15"),
("M16", "M16"),
)
#to be updated with domains from DSO
......
......@@ -22,10 +22,10 @@ NUMBER_UNITS_CHOICES = (("",""), ("METERS","METERS"), ("KILOMETERS","KILOMETERS"
TIME_UNITS_CHOICES = (("SECONDS","SECONDS"), ("MINUTES","MINUTES"), ("MILLISECONDS","MILLISECONDS"))
FLOW_CHOICES = get_instances("SAO#Flow")
# FLOW returns ()
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"))
S5_6_CHOICES = (("at even intervals","AT EVEN INTERVALS"), ("sequentially","SEQUENTIALLY"))
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"))
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
......
......@@ -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.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()
def getclassofmain(main):
return(findclassofmain(main))
def inferencing(boilerlate, prefix, main, suffix):
def inferencing(project, boilerlate, prefix, main, suffix):
listofboil = []
listofprefix = []
listofmain = []
......@@ -21,25 +27,40 @@ def inferencing(boilerlate, prefix, main, suffix):
for i in suffix:
listofsuffix.append(list(i.values()))
#findclassofmain(listofmain)
exportboiltottl(listofboil, findclassofmain(listofmain))
print("inferencing...")
exportboiltottl(project, listofprefix, listofboil, listofmain, listofsuffix)
#print(project)
#print(listofboil[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#")
rdo = URIRef("http://delab.csd.auth.gr/ontologies/2018/RDO#")
rbo = URIRef("http://delab.csd.auth.gr/ontologies/2018/RBO#")
g = Graph()
g.load(Ontology_file, format="turtle")
#for b in boilerplate:
for i in range(len(boilerplate)):
title = boilerplate[i][0]['title']
#title = BNode()
g.add((per_instances + title, RDF.type, rdo + 'Requirement'))
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'])))
print(g.serialize(format="turtle").decode("utf-8"))
#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"))
def findclassofmain(listofmain):
......@@ -48,11 +69,12 @@ def findclassofmain(listofmain):
verbsmain = main_syntax[('M'+str(i+1))]['Verbs']
subsmain = main_syntax[('M'+str(i+1))]['Subject']
attrsmain = main_syntax[('M'+str(i+1))]['Attributes']
for currentmain in range(len(listofmain)):
currentverb = listofmain[currentmain][0]['verb']
currentsubject = listofmain[currentmain][0]['sys_fun_inter']
currentattr = listofmain[currentmain][0]['sys_fun_inter']
#for currentmain in range(len(listofmain)):
currentverb = listofmain['verb']
currentsubject = listofmain['sys_fun_inter']
currentattr = listofmain['sys_fun_inter']
for verbmain in verbsmain:
flag = 0
if (verbmain.upper() == currentverb.upper()):
for submain in subsmain:
flag = 0
......@@ -77,32 +99,34 @@ def findclassofmain(listofmain):
for sys in FLOW_CHOICES:
if sys[0] == currentattr:
classlist.append('M'+str(i+1))
break
return(classlist)
if attrmain == "Item":
for sys in ITEM_CHOICES:
if sys[0] == currentattr:
classlist.append('M'+str(i+1))
break
return(classlist)
if attrmain == "Function":
for sys in FUNCTION_CHOICES:
if sys[0] == currentattr:
classlist.append('M'+str(i+1))
break
return(classlist)
if attrmain == "System":
for sys in SYSTEM_CHOICES:
if sys[0] == currentattr:
classlist.append('M'+str(i+1))
break
return(classlist)
if attrmain == "Interface":
for sys in INTERFACE_CHOICES:
if sys[0] == currentattr:
classlist.append('M'+str(i+1))
break
return(classlist)
if attrmain == "State":
for sys in (STATE_CHOICES+ STATE_SET_CHOICES):
if sys[0] == currentattr:
classlist.append('M'+str(i+1))
break
return(classlist)
classlist.append("ERROR")
return classlist
......@@ -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.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.views import APIView
......@@ -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.requirements import BoilerplateData
from rest_framework.exceptions import APIException
class MainListAPIView(ListAPIView):
"""
......@@ -62,11 +65,14 @@ class MainDetailsAPIView(RetrieveUpdateDestroyAPIView):
#add data in thn Model BoilerplateData
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 )
serializer.save()
#print(self.new.changed_data)
#instance = serializer.save()
#write_fuseki = fuseki.FusekiActions()
#write_fuseki.write(serializer.data)
curmain_choices = inference.getclassofmain(instance)
#instance['main_choices'] = curmain_choices[0]
if curmain_choices[0] == 'ERROR':
raise APIException("Main choices not in [M1-M16]")
else:
instance = serializer.save(main_choices = curmain_choices[0])
#Custom actions when DELETE
def perform_destroy(self, instance):
......
......@@ -229,6 +229,7 @@ class InferDetailsAPIView(RetrieveUpdateDestroyAPIView):
#Custom actions when PUT
def perform_update(self, serializer):
instance = serializer.validated_data
project_title = ""
boildata= []
prefixdata = []
maindata = []
......@@ -236,13 +237,14 @@ class InferDetailsAPIView(RetrieveUpdateDestroyAPIView):
#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']).
#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)
for id in prefix:
boildata.append(self.getboildata(id.boilerplate_data_id.id))
prefixdata.append(self.getprefixdata(id.boilerplate_data_id.id))
maindata.append(self.getmaindata(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)
#inference.inferencing(prefix)
instance.update(inference_data = "aaaoooaaa" )
......
......@@ -15,6 +15,7 @@ from rest_framework.response import Response
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 NUMERICAL_AFFIRMATIVE_CHOICES, S2_CHOICES, S3_CHOICES, S4_CHOICES, S5_6_CHOICES
from reqman.apps.reqtool.models.requirements import BoilerplateData
......@@ -60,7 +61,8 @@ class SuffixDetailsAPIView(RetrieveUpdateDestroyAPIView):
#add data in thn Model BoilerplateData
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 )
serializer.save()
ssuffix_choice = self.getclassofsuffix(instance["s_choices"])
serializer.save(suffix_choices = ssuffix_choice)
#print(self.new.changed_data)
#instance = serializer.save()
#write_fuseki = fuseki.FusekiActions()
......@@ -73,6 +75,25 @@ class SuffixDetailsAPIView(RetrieveUpdateDestroyAPIView):
#print("deleted")
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):
......
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