Commit fe2267a1 authored by Thodoris Nestoridis's avatar Thodoris Nestoridis

Prefix [Backend - Frontend] - Get syntax/verbs

parent 4d94a6cf
...@@ -2951,7 +2951,23 @@ RBO:P3 ...@@ -2951,7 +2951,23 @@ RBO:P3
a owl:Class ; a owl:Class ;
rdfs:comment "As long as <time period>" ; rdfs:comment "As long as <time period>" ;
rdfs:subClassOf RBO:SimplePrefix ; rdfs:subClassOf RBO:SimplePrefix ;
rdfs:subClassOf [
a owl:Restriction ;
owl:allValuesFrom RBO:OccuringFunctionality ;
owl:onProperty RBO:isRelatedToPlaceholder ;
] ;
rdfs:subClassOf [
a owl:Restriction ;
owl:cardinality "1"^^xsd:nonNegativeInteger ;
owl:onProperty RBO:isRelatedToOccuringFunctionality ;
] ;
rdfs:subClassOf [
a owl:Restriction ;
owl:cardinality "1"^^xsd:nonNegativeInteger ;
owl:onProperty RBO:isRelatedToPlaceholder ;
] ;
. .
RBO:PerformOccuringFunctionality RBO:PerformOccuringFunctionality
a owl:Class ; a owl:Class ;
rdfs:comment "<system> performs <function>" ; rdfs:comment "<system> performs <function>" ;
......
...@@ -39,6 +39,9 @@ export class AddBoilerplateComponent implements OnInit { ...@@ -39,6 +39,9 @@ export class AddBoilerplateComponent implements OnInit {
has_main: this.boilerplate.has_main, has_main: this.boilerplate.has_main,
has_suffix: this.boilerplate.has_suffix has_suffix: this.boilerplate.has_suffix
}; };
if (data.title != "") {
data.title = data.title?.replace(/[^\w\s]/gi, ' ')
data.title = data.title?.replace(/ /g,"_")}
this.boilerplatelService.create(this.route.snapshot.params.gb, data) this.boilerplatelService.create(this.route.snapshot.params.gb, data)
.subscribe( .subscribe(
......
...@@ -68,6 +68,9 @@ export class BoilerplateDetailsComponent implements OnInit { ...@@ -68,6 +68,9 @@ export class BoilerplateDetailsComponent implements OnInit {
} }
updateBoilerplate(): any { updateBoilerplate(): any {
if (this.currentboilerplate.title != "") {
this.currentboilerplate.title = this.currentboilerplate.title ?.replace(/[^\w\s]/gi, ' ')
this.currentboilerplate.title = this.currentboilerplate.title?.replace(/ /g,"_")}
this.boilerplateService.update(this.route.snapshot.params.gb, this.currentboilerplate.id, this.currentboilerplate) this.boilerplateService.update(this.route.snapshot.params.gb, this.currentboilerplate.id, this.currentboilerplate)
.subscribe( .subscribe(
......
...@@ -33,11 +33,11 @@ export class BoilerplateListComponent implements OnInit { ...@@ -33,11 +33,11 @@ export class BoilerplateListComponent implements OnInit {
type: 'pie', type: 'pie',
radius: ['40%', '70%'], radius: ['40%', '70%'],
data: [ data: [
{value: 1048, name: '1'}, {value: 0, name: '1'},
{value: 735, name: '2'}, {value: 0, name: '2'},
{value: 580, name: '3'}, {value: 0, name: '3'},
{value: 484, name: '4'}, {value: 0, name: '4'},
{value: 300, name: '5'} ] {value: 0, name: '5'} ]
}, },
], ],
}; };
......
...@@ -8,8 +8,10 @@ from reqman.apps.reqtool.rest_api.services.parse_ontologies import * ...@@ -8,8 +8,10 @@ from reqman.apps.reqtool.rest_api.services.parse_ontologies import *
from pygments.formatters.html import HtmlFormatter from pygments.formatters.html import HtmlFormatter
from pygments import highlight from pygments import highlight
#get prefix syntax from the Onotlogy #get prefix syntax from the Onotlogy#
get_prefix_syntax() #print(get_prefix_new_syntax())
PREFIX_SYNTAX = get_prefix_syntax()
SIMPLE_PREFIX_CHOICES = ( ("",""), SIMPLE_PREFIX_CHOICES = ( ("",""),
("P1", "If/Unless <logical expression>"), ("P1", "If/Unless <logical expression>"),
...@@ -27,7 +29,9 @@ LOGICAL_EXPRESSION = ( ("",""), ...@@ -27,7 +29,9 @@ LOGICAL_EXPRESSION = ( ("",""),
("occuring functionality", "occuring functionality") ("occuring functionality", "occuring functionality")
) )
VERB_CHOICES = get_verb_instances("LO#Verb")
VERB_CHOICES_PREFIX = get_prefix_verbs()
#Must read this info from the Ontology #Must read this info from the Ontology
PREFIX_CHOICES = ( ("If", "If"), ("Unless", "Unless"), PREFIX_CHOICES = ( ("If", "If"), ("Unless", "Unless"),
...@@ -142,7 +146,7 @@ class Prefix(models.Model): ...@@ -142,7 +146,7 @@ class Prefix(models.Model):
prefix = models.CharField(choices=PREFIX_CHOICES, max_length=100) prefix = models.CharField(choices=PREFIX_CHOICES, max_length=100)
#state value constraint #state value constraint
system_fun_item = models.CharField(choices= (ITEM_CHOICES + SYSTEM_CHOICES + FUNCTION_CHOICES), max_length=100) system_fun_item = models.CharField(choices= (ITEM_CHOICES + SYSTEM_CHOICES + FUNCTION_CHOICES), max_length=100)
state_or_verb = models.CharField(choices=STATE_CHOICES + VERB_CHOICES, max_length=100) state_or_verb = models.CharField(choices=STATE_CHOICES + VERB_CHOICES_PREFIX, max_length=100)
#state_value = models.CharField(choices=STATE_VALUE_CHOICES, 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=, max_length=100, blank=True) #sys_fun = models.CharField(choices=, max_length=100, blank=True)
......
...@@ -10,9 +10,13 @@ Ontology_file = "../../Ontologies/Autonomy_v1.ttl" ...@@ -10,9 +10,13 @@ Ontology_file = "../../Ontologies/Autonomy_v1.ttl"
list_of_inference_metrics = ["IncompleteRequirement", "AmbiguousRequirement", list_of_inference_metrics = ["IncompleteRequirement", "AmbiguousRequirement",
"InconsistentRequirement","NoisyRequirement","OpaqueRequirement","RedundantRequirement"] "InconsistentRequirement","NoisyRequirement","OpaqueRequirement","RedundantRequirement"]
prefix_syntax = get_prefix_syntax()
main_syntax = get_main_sytax_inference() main_syntax = get_main_sytax_inference()
def getclassofprefix(prefix):
return(findclassofprefix(prefix))
def getclassofmain(main): def getclassofmain(main):
return(findclassofmain(main)) return(findclassofmain(main))
...@@ -126,6 +130,34 @@ def shacl(ontotlogy_file): ...@@ -126,6 +130,34 @@ def shacl(ontotlogy_file):
print(metrics_dict) print(metrics_dict)
return(metrics_dict) return(metrics_dict)
'''Find if the Prefix exists in syntax'''
def findclassofprefix(listofprefix):
classlist=[]
currentverb = listofprefix['state_or_verb'].rsplit(' : ', 1)
currentsubject = listofprefix['system_fun_item']
currentattr = listofprefix['item_function_flow_statevalue']
for prefix in prefix_syntax:
for inprefix in prefix_syntax[prefix]:
if currentverb[1] in prefix_syntax[prefix][inprefix]:
if currentsubject.split(":")[0].strip() in prefix_syntax[prefix][inprefix.split("_")[0]+"_Subject"]:
if currentattr.split(":")[0].strip() in prefix_syntax[prefix][inprefix.split("_")[0]+"_Attribute"]:
if listofprefix['prefix'] == "If":
return "P1"
if listofprefix['prefix'] == "As soon as":
return "P2"
if listofprefix['prefix'] == "As long as":
return "P3"
if listofprefix['prefix'] == "Once":
return "P1"
if listofprefix['prefix'] == "Unless":
return "P1"
return(prefix)
classlist.append("ERROR")
return classlist
'''Find if the Main exists in syntax'''
def findclassofmain(listofmain): def findclassofmain(listofmain):
classlist = [] classlist = []
for i in range(len(main_syntax)): for i in range(len(main_syntax)):
......
...@@ -547,11 +547,14 @@ def get_prefix_syntax(): ...@@ -547,11 +547,14 @@ def get_prefix_syntax():
prefix_list.extend(get_instances_list(prefix)) prefix_list.extend(get_instances_list(prefix))
for prefix in prefix_list: for prefix in prefix_list:
prefix_dict[prefix] = {} prefix_dict[prefix] = {}
prefix_dict[prefix]["Verbs"] = [] #prefix_dict[prefix]["Verbs"] = []
#prefix_dict[prefix]["Attribute"] = []
#prefix_dict[prefix]["Subject"] = []
bnodes_uriref = find_triples(prefix) bnodes_uriref = find_triples(prefix)
subclass_data = [] subclass_data = []
for per in bnodes_uriref: for per in bnodes_uriref:
tmp = get_instances_list(str(per)) tmp = get_instances_list(str(per))
bnodes_uriref.extend(tmp)
for i in tmp: for i in tmp:
subclass_data.append(i) subclass_data.append(i)
for pre in subclass_data: for pre in subclass_data:
...@@ -574,20 +577,104 @@ def get_prefix_syntax(): ...@@ -574,20 +577,104 @@ def get_prefix_syntax():
isrelated.append(i) isrelated.append(i)
else: else:
sub.append(i) sub.append(i)
if len(sub)>1 :
prefix_dict[prefix][str(pre)+"_Verbs"] = []
prefix_dict[prefix][str(pre)+"_Attribute"] = []
prefix_dict[prefix][str(pre)+"_Subject"] = []
# if pre is StateValueConstraint we know that Atribute is StateValue
if "StateValue" in str(pre) and len(sub)>1:
prefix_dict[prefix][str(pre)+"_Attribute"].append("StateValue")
sub.remove("StateValue")
else:
for i in sub: for i in sub:
for j in isrelated: for j in isrelated:
if i in j: if i in j:
prefix_dict[prefix]["Attribute"] = i if i not in prefix_dict[prefix][str(pre)+"_Attribute"]:
prefix_dict[prefix][str(pre)+"_Attribute"].append(i)
sub.remove(i) sub.remove(i)
#add verbs
if tmp_list2: if tmp_list2:
ver = get_verb(tmp_list2) ver = get_verb(tmp_list2)
prefix_dict[prefix]["Verbs"].append(ver) if (len(ver)==0):
#for i in ver: prefix_dict[prefix][str(pre)+"_Verbs"].append('is')
# sub.remove(i) else:
prefix_dict[prefix]["Suject"] = sub prefix_dict[prefix][str(pre)+"_Verbs"].extend(ver)
for j in tmp_list2:
if "LO" in str(j):
sub.remove(j.split("#")[1])
#Subjects are everything that is not a verb or an attribute - may some erros here
for newsub in sub:
if newsub not in prefix_dict[prefix][str(pre)+"_Subject"]:
if (len(prefix_dict[prefix][str(pre)+"_Attribute"]) == 0 and len(sub)>=2):
prefix_dict[prefix][str(pre)+"_Attribute"].append(sub[len(sub) -2])
sub.pop(len(sub) -2)
else:
prefix_dict[prefix][str(pre)+"_Subject"].append(newsub)
return prefix_dict return prefix_dict
'''Return Verb list Of Prefixes'''
def get_prefix_verbs():
prefix_dict={}
prefix_list = []
verblist =[]
out_list = []
get_prefix = get_instances_list("RBO#Prefix")
for prefix in get_prefix:
prefix_list.extend(get_instances_list(prefix))
for prefix in prefix_list:
bnodes_uriref = find_triples(prefix)
subclass_data = []
for per in bnodes_uriref:
tmp = get_instances_list(str(per))
bnodes_uriref.extend(tmp)
for i in tmp:
subclass_data.append(i)
for pre in subclass_data:
tmp_list2 = find_triples(pre)
tmp_list2 = [str(i) for i in tmp_list2]
#add verbs
if tmp_list2:
ver = get_verb(tmp_list2)
if (len(ver)==0):
out_list.append('Is : is')
verblist.append('Is : is')
else:
verblist.extend(ver)
for extra in tmp_list2:
if "LO" in str(extra):
per = URIRef(extra)
for s, p, o in g.triples((None, RDF.type, per)):
spl = s.split("#")
out_list.append(extra.split("#")[1] + " : " + str(spl[1]))
return tuple((str(n), str(n)) for n in (set(out_list)))
'''The new prefix syntaxt parser'''
def get_prefix_new_syntax():
bnodes = []
prefix_list = []
get_prefix = get_instances_list("RBO#Prefix")
for prefix in get_prefix:
prefix_list.extend(get_instances_list(prefix))
#owl:allValuesFrom
for prefix in prefix_list:
per = URIRef("http://delab.csd.auth.gr/ontologies/2018/RBO#" + prefix)
#per2 = URIRef("http://www.w3.org/2002/07/owl#allValuesFrom")
bnodes_uriref = find_triples(prefix)
subclass_data = []
#print(bnodes_uriref)
for per in bnodes_uriref:
tmp = get_instances_list(str(per))
bnodes_uriref.extend(tmp)
for i in tmp:
subclass_data.append(i)
print(subclass_data)
#
'''Find the triples of the prefix - return list.type(URIRef)''' '''Find the triples of the prefix - return list.type(URIRef)'''
def find_triples(prefix): def find_triples(prefix):
bnodes = [] bnodes = []
......
...@@ -5,8 +5,8 @@ from django.http import HttpResponse, JsonResponse ...@@ -5,8 +5,8 @@ from django.http import HttpResponse, JsonResponse
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
from rest_framework.parsers import JSONParser from rest_framework.parsers import JSONParser
from reqman.apps.reqtool.models.requirements import Prefix, Boilerplate, BoilerplateGroup, PREFIX_CHOICES, LOGIC_CONNECTIVE, VERB_CHOICES from reqman.apps.reqtool.models.requirements import Prefix, Boilerplate, BoilerplateGroup, PREFIX_CHOICES, LOGIC_CONNECTIVE
from reqman.apps.reqtool.models.requirements import VERB_CHOICES, ITEM_CHOICES, SYSTEM_CHOICES, FUNCTION_CHOICES, STATE_CHOICES from reqman.apps.reqtool.models.requirements import VERB_CHOICES_PREFIX, ITEM_CHOICES, SYSTEM_CHOICES, FUNCTION_CHOICES, STATE_CHOICES
from reqman.apps.reqtool.models.requirements import ITEM_CHOICES, FLOW_CHOICES, FUNCTION_CHOICES, STATE_VALUE_CHOICES from reqman.apps.reqtool.models.requirements import ITEM_CHOICES, FLOW_CHOICES, FUNCTION_CHOICES, STATE_VALUE_CHOICES
from reqman.apps.reqtool.models.requirements import BoilerplateData, InferenceResults from reqman.apps.reqtool.models.requirements import BoilerplateData, InferenceResults
...@@ -19,6 +19,7 @@ from reqman.apps.reqtool.rest_api.services import fuseki, inference ...@@ -19,6 +19,7 @@ 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
from rest_framework.exceptions import APIException
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
...@@ -183,8 +184,11 @@ class PrefixDetailsAPIView(RetrieveUpdateDestroyAPIView): ...@@ -183,8 +184,11 @@ class PrefixDetailsAPIView(RetrieveUpdateDestroyAPIView):
ei_instance = instance['item_function_flow_statevalue'].rsplit(':', 1) ei_instance = instance['item_function_flow_statevalue'].rsplit(':', 1)
pr = (instance['prefix'] + ' ' + es_instance[len(es_instance)-1] + ' ' + ev_instance[len(ev_instance)-1] + ' ' + ei_instance[len(ei_instance)-1]) pr = (instance['prefix'] + ' ' + es_instance[len(es_instance)-1] + ' ' + ev_instance[len(ev_instance)-1] + ' ' + ei_instance[len(ei_instance)-1])
BoilerplateData.objects.filter(owner_data=instance['prefix_boilerplate'].owner, boilerplate_data_id = instance['prefix_boilerplate']).update(prefix_data = pr ) BoilerplateData.objects.filter(owner_data=instance['prefix_boilerplate'].owner, boilerplate_data_id = instance['prefix_boilerplate']).update(prefix_data = pr )
sprefix = self.simple_prefix(instance["prefix"]) prefix_choices = inference.getclassofprefix(instance)
serializer.save(simple_prefix = sprefix) if prefix_choices[0] == 'ERROR':
raise APIException("Prefix choices not in [P1-P3]")
else:
serializer.save(simple_prefix = prefix_choices[0])
#Custom actions when DELETE #Custom actions when DELETE
...@@ -255,7 +259,7 @@ class InferDetailsAPIView(RetrieveUpdateDestroyAPIView): ...@@ -255,7 +259,7 @@ class InferDetailsAPIView(RetrieveUpdateDestroyAPIView):
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))
metrics = inference.inferencing(project_title, boildata, prefixdata, maindata, suffixdata) metrics, onto_file = 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 = metrics) instance.update(inference_data = metrics)
...@@ -289,7 +293,7 @@ class LogConChoicesViewSet(APIView): ...@@ -289,7 +293,7 @@ class LogConChoicesViewSet(APIView):
class VerbChoicesViewSet(APIView): class VerbChoicesViewSet(APIView):
def get(self, request): def get(self, request):
response = Response(STATE_CHOICES + VERB_CHOICES) response = Response(STATE_CHOICES + VERB_CHOICES_PREFIX)
return response return response
class FunItemSysChoicesViewSet(APIView): class FunItemSysChoicesViewSet(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