Commit c22fcd4e authored by Thodoris Nestoridis's avatar Thodoris Nestoridis

inference write has_main in ontology (needs - has_prefix, has_suffix)

parent 4de390ff
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
def inferencing(prefix):
print(prefix.values_list())
for course in prefix:
print("this", course['system_fun_item'])
from rdflib import Graph, BNode
from rdflib.namespace import RDFS
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
main_syntax = get_main_sytax()
def inferencing(boilerlate, prefix, main, suffix):
listofboil = []
listofprefix = []
listofmain = []
listofsuffix = []
for i in boilerlate:
listofboil.append(list(i.values()))
for i in prefix:
listofprefix.append(list(i.values()))
for i in main:
listofmain.append(list(i.values()))
for i in suffix:
listofsuffix.append(list(i.values()))
#findclassofmain(listofmain)
exportboiltottl(listofboil, findclassofmain(listofmain))
print("inferencing...")
#print(listofboil[0][0]['id'])
#print(listofprefix[0][0]['id'])
def exportboiltottl(boilerplate, classofmain):
per_instances = URIRef("http://delab.csd.auth.gr/ontologies/2018/RDO-instances#")
rdo = URIRef("http://delab.csd.auth.gr/ontologies/2018/RDO#")
g = Graph()
#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])))
print(g.serialize(format="turtle").decode("utf-8"))
def findclassofmain(listofmain):
classlist = []
for i in range(len(main_syntax)):
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 verbmain in verbsmain:
if (verbmain.upper() == currentverb.upper()):
for submain in subsmain:
flag = 0
if submain == "System":
for sys in SYSTEM_CHOICES:
if sys[0] == currentsubject:
flag = 1
break
if submain == "Function":
for sys in FUNCTION_CHOICES:
if sys[0] == currentsubject:
flag = 1
break
if submain == "Interface":
for sys in INTERFACE_CHOICES:
if sys[0] == currentsubject:
flag = 1
break
if flag == 1 :
for attrmain in attrsmain:
if attrmain == "Flow":
for sys in FLOW_CHOICES:
if sys[0] == currentattr:
classlist.append('M'+str(i+1))
break
if attrmain == "Item":
for sys in ITEM_CHOICES:
if sys[0] == currentattr:
classlist.append('M'+str(i+1))
break
if attrmain == "Function":
for sys in FUNCTION_CHOICES:
if sys[0] == currentattr:
classlist.append('M'+str(i+1))
break
if attrmain == "System":
for sys in SYSTEM_CHOICES:
if sys[0] == currentattr:
classlist.append('M'+str(i+1))
break
if attrmain == "Interface":
for sys in INTERFACE_CHOICES:
if sys[0] == currentattr:
classlist.append('M'+str(i+1))
break
if attrmain == "State":
for sys in (STATE_CHOICES+ STATE_SET_CHOICES):
if sys[0] == currentattr:
classlist.append('M'+str(i+1))
break
return classlist
......@@ -12,7 +12,11 @@ from reqman.apps.reqtool.models.requirements import BoilerplateData, InferenceRe
from reqman.apps.reqtool.rest_api.serializers.requirements import BoilerplateSerializer, PrefixSerializer, BoilerplateDataSerializer, BoilerplateGroupSerializer, InferSerializer
from reqman.apps.permissions import IsOwnerOrReadOnly
from reqman.apps.reqtool.models.main_req import Main
from reqman.apps.reqtool.models.suffix_req import Suffix
from reqman.apps.reqtool.rest_api.services import fuseki, inference
from rest_framework.response import Response
from rest_framework.views import APIView
......@@ -225,29 +229,37 @@ class InferDetailsAPIView(RetrieveUpdateDestroyAPIView):
#Custom actions when PUT
def perform_update(self, serializer):
instance = serializer.validated_data
#add data in thn Model BoilerplateData
boildata= []
prefixdata = []
maindata = []
suffixdata = []
#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)
prefix = BoilerplateData.objects.filter(group_of_boilerplate_data = instance['infer_group_of_boilerplate'].id)
for id in prefix:
print(id.boilerplate_data_id.id)
data = self.getdata(id.boilerplate_data_id.id)
print(data)
#from here i can get the values of the last prefix
for i in data:
print(i.system_fun_item)
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)
#print(prefix[0].boilerplate_data_id.id)
#inference.inferencing(prefix)
instance.update(inference_data = "aaaoooaaa" )
#sprefix = self.simple_prefix(instance["prefix"])
serializer.save()
def getdata(self, pr):
prefix = ""
prefix = (Prefix.objects.filter(prefix_boilerplate = pr))
return prefix
def getboildata(self, pr):
return (Boilerplate.objects.filter(id = pr))
def getprefixdata(self, pr):
return (Prefix.objects.filter(prefix_boilerplate = pr))
def getmaindata(self, pr):
return (Main.objects.filter(boilerplate_of_main = pr))
def getsuffixdata(self, pr):
return (Suffix.objects.filter(boilerplate_of_suffix = pr))
class PrefixChoicesViewSet(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