Commit 0dae831e authored by Thodoris Nestoridis's avatar Thodoris Nestoridis

RFT v0.2

parent 08bac18c
...@@ -110,7 +110,8 @@ ...@@ -110,7 +110,8 @@
</mat-panel-description> </mat-panel-description>
</mat-expansion-panel-header> </mat-expansion-panel-header>
{{ item.Comment }} {{ item.Comment }}
<ul> <h4><b>Instances</b></h4> <ul>
<button mat-button [matMenuTriggerFor]="menu" #menuTrigger><h4><b>Instances</b></h4></button>
<div *ngFor="let instan of item.Instance_of_Class| filter:searchText"> <div *ngFor="let instan of item.Instance_of_Class| filter:searchText">
<li> <li>
<mat-expansion-panel hideToggle> <mat-expansion-panel hideToggle>
...@@ -180,4 +181,7 @@ ...@@ -180,4 +181,7 @@
</div> </div>
</div> </div>
</mat-grid-list > </mat-grid-list >
\ No newline at end of file <mat-menu #menu="matMenu">
<button mat-menu-item >Add Instances</button>
</mat-menu>
\ No newline at end of file
...@@ -11,6 +11,7 @@ import { NotifierService } from "angular-notifier"; ...@@ -11,6 +11,7 @@ import { NotifierService } from "angular-notifier";
@Component({ @Component({
selector: 'app-boilerplate-details', selector: 'app-boilerplate-details',
templateUrl: './boilerplate-details.component.html', templateUrl: './boilerplate-details.component.html',
...@@ -50,7 +51,7 @@ export class BoilerplateDetailsComponent implements OnInit { ...@@ -50,7 +51,7 @@ export class BoilerplateDetailsComponent implements OnInit {
ngOnInit(): void { ngOnInit(): void {
this.message = ''; this.message = '';
this.getchoices(); this.getchoices(this.route.snapshot.params.gb);
this.getBoilerplate(this.route.snapshot.params.gb, this.route.snapshot.params.id); this.getBoilerplate(this.route.snapshot.params.gb, this.route.snapshot.params.id);
} }
...@@ -105,12 +106,14 @@ export class BoilerplateDetailsComponent implements OnInit { ...@@ -105,12 +106,14 @@ export class BoilerplateDetailsComponent implements OnInit {
} }
} }
getchoices(): void{ getchoices(gb : any): void{
//System //System
this.mainService.getdictionary() this.mainService.getdictionary(gb)
.subscribe( .subscribe(
data => { data => {
this.systems = data // console.log(data[0].Dictionary_Data);
this.systems = data[0].Dictionary_Data
}, },
error => { error => {
console.log(error); console.log(error);
......
...@@ -8,6 +8,7 @@ import { ActivatedRoute, Router } from '@angular/router'; ...@@ -8,6 +8,7 @@ import { ActivatedRoute, Router } from '@angular/router';
import {MatTableDataSource} from '@angular/material/table'; import {MatTableDataSource} from '@angular/material/table';
import {MatPaginator} from '@angular/material/paginator'; import {MatPaginator} from '@angular/material/paginator';
import { EChartsOption } from 'echarts'; import { EChartsOption } from 'echarts';
import { NotifierService } from "angular-notifier";
...@@ -41,7 +42,7 @@ export class BoilerplateListComponent implements OnInit { ...@@ -41,7 +42,7 @@ export class BoilerplateListComponent implements OnInit {
}, },
], ],
}; };
private readonly notifier: NotifierService;
boilerplates?: Boilerplate[]; boilerplates?: Boilerplate[];
boilerplatesdata?: BoilerplateData[]; boilerplatesdata?: BoilerplateData[];
currentBoilerplate?: Boilerplate; currentBoilerplate?: Boilerplate;
...@@ -73,7 +74,9 @@ export class BoilerplateListComponent implements OnInit { ...@@ -73,7 +74,9 @@ export class BoilerplateListComponent implements OnInit {
suffix: any; suffix: any;
constructor(private boilerplateService: BoilerplateService, private prefixService: PrefixService, private route: ActivatedRoute, constructor(private boilerplateService: BoilerplateService, private prefixService: PrefixService, private route: ActivatedRoute,
private router: Router) { } private router: Router, notifierService: NotifierService) { this.notifier = notifierService;
}
ngOnInit(): void { ngOnInit(): void {
this.retrieveBoilerplates(); this.retrieveBoilerplates();
...@@ -189,6 +192,7 @@ export class BoilerplateListComponent implements OnInit { ...@@ -189,6 +192,7 @@ export class BoilerplateListComponent implements OnInit {
console.log(error); console.log(error);
this.showSpinner = !this.showSpinner; this.showSpinner = !this.showSpinner;
this.exporting = !this.exporting this.exporting = !this.exporting
this.notifier.notify("warning",(JSON.stringify(error["error"]["detail"])));
}); });
} }
......
...@@ -29,6 +29,8 @@ export class InstancesListComponent implements OnInit { ...@@ -29,6 +29,8 @@ export class InstancesListComponent implements OnInit {
ngOnInit(): void { ngOnInit(): void {
this.getchoices(); this.getchoices();
console.log('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
} }
......
...@@ -174,7 +174,7 @@ ...@@ -174,7 +174,7 @@
<div class="col"> <div class="col">
<form class="form-group form-inline" [ngStyle]="(stsysconsetControlisDivVisible) ? {'visibility': 'visible'} : {'visibility': 'hidden'}"> <form class="form-group form-inline" [ngStyle]="(stsysconsetControlisDivVisible) ? {'visibility': 'visible'} : {'visibility': 'hidden'}">
<mat-form-field class="example-full-width"> <mat-form-field class="example-full-width">
<mat-label *ngIf="stsysconsetControl.value !=null">Connection : {{stsysconsetControl.value.slice(0, stsysconsetControl.value.indexOf(':'))}}</mat-label> <mat-label *ngIf="stsysconsetControl.value !=null">StateSet or StateValue or System or Connection : {{stsysconsetControl.value.slice(0, stsysconsetControl.value.indexOf(':'))}}</mat-label>
<input <input
placeholder="Pick one" placeholder="Pick one"
aria-label="Number" aria-label="Number"
......
...@@ -4,6 +4,7 @@ import { Observable } from 'rxjs'; ...@@ -4,6 +4,7 @@ import { Observable } from 'rxjs';
import { Main } from '../models/main.model'; import { Main } from '../models/main.model';
const baseUrl = 'http://155.207.131.19:8000/api-auth/groupboilerplates/0/boilerplates/'; const baseUrl = 'http://155.207.131.19:8000/api-auth/groupboilerplates/0/boilerplates/';
const baseUrl2 = 'http://155.207.131.19:8000/api-auth/groupboilerplates/';
const Url = '/main/'; const Url = '/main/';
@Injectable({ @Injectable({
...@@ -32,6 +33,9 @@ export class MainService { ...@@ -32,6 +33,9 @@ export class MainService {
delete(boilerplate: any, id: any): Observable<any> { delete(boilerplate: any, id: any): Observable<any> {
return this.http.delete(`${baseUrl}${boilerplate}${Url}${baseUrl}${id}`); return this.http.delete(`${baseUrl}${boilerplate}${Url}${baseUrl}${id}`);
} }
getmain(gb: any): Observable<any> {
return this.http.get(`${baseUrl2}${gb}${Url}`+`choices/`);
}
getsubject(): Observable<any> { getsubject(): Observable<any> {
return this.http.get(`http://155.207.131.19:8000/api-auth/main/choices/subject/`); return this.http.get(`http://155.207.131.19:8000/api-auth/main/choices/subject/`);
...@@ -153,8 +157,8 @@ export class MainService { ...@@ -153,8 +157,8 @@ export class MainService {
return this.http.get(`http://155.207.131.19:8000/api-auth/class/state/instance`); return this.http.get(`http://155.207.131.19:8000/api-auth/class/state/instance`);
} }
getdictionary(): Observable<any> { getdictionary(gb : any): Observable<any> {
return this.http.get(`http://155.207.131.19:8000/api-auth/dictionary`); return this.http.get(`${baseUrl2}${gb}`+`/dictionary/`);
} }
getmainsyntax(): Observable<any> { getmainsyntax(): Observable<any> {
......
...@@ -34,15 +34,15 @@ MAIN_CHOICES = ( ("",""), ("M1", "M1"), ...@@ -34,15 +34,15 @@ MAIN_CHOICES = ( ("",""), ("M1", "M1"),
#to be updated with domains from DSO #to be updated with domains from DSO
#SYSTEM #SYSTEM
SYSTEM_CHOICES = get_instances("SAO#System") #+get_i_instances("SAO#System") #SYSTEM_CHOICES = get_instances("SAO#System") #+get_i_instances("SAO#System")
SYSTEM_CLASSES_COMMENTS = get_dmo_classes_and_comment("SAO#System") #SYSTEM_CLASSES_COMMENTS = get_dmo_classes_and_comment("SAO#System")
SYSTEM_SUBCLASSES_COMMENTS = get_dmo_classes_of_classes_and_comment("SAO#System") #SYSTEM_SUBCLASSES_COMMENTS = get_dmo_classes_of_classes_and_comment("SAO#System")
SYSTEM_INSTANCES_COMMENTS = get_dmo_instance_and_comment("SAO#System") #SYSTEM_INSTANCES_COMMENTS = get_dmo_instance_and_comment("SAO#System")
#FUNTION #FUNTION
FUNCTION_CHOICES = get_instances("SAO#Function") #FUNCTION_CHOICES = get_instances("SAO#Function")
FUNCTION_CLASSES_COMMENTS = get_dmo_classes_and_comment("SAO#Function") #FUNCTION_CLASSES_COMMENTS = get_dmo_classes_and_comment("SAO#Function")
FUNCTION_SUBCLASSES_COMMENTS = get_dmo_classes_of_classes_and_comment("SAO#Function") #FUNCTION_SUBCLASSES_COMMENTS = get_dmo_classes_of_classes_and_comment("SAO#Function")
FUNCTION_INSTANCES_COMMENTS = get_dmo_instance_and_comment("SAO#Function") #FUNCTION_INSTANCES_COMMENTS = get_dmo_instance_and_comment("SAO#Function")
# #
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"),
...@@ -51,41 +51,41 @@ QUANTIFIER_CHOICES = ( ("None","None"), ("All", "All"), ("Only", "Only"), ...@@ -51,41 +51,41 @@ QUANTIFIER_CHOICES = ( ("None","None"), ("All", "All"), ("Only", "Only"),
) )
NUMBER_UNITS_CHOICES = (("",""),("m/s","m/s"), ("m/s^2","m/s^2"), ("m/s^3","m/s^3"), ("rad","rad"), ("rad/s","rad/s"), ("Hz","Hz"), ("METERS","METERS"), ("KILOMETERS","KILOMETERS"), ("VOLT","VOLT"), ("Number", "Number")) NUMBER_UNITS_CHOICES = (("",""),("m/s","m/s"), ("m/s^2","m/s^2"), ("m/s^3","m/s^3"), ("rad","rad"), ("rad/s","rad/s"), ("Hz","Hz"), ("METERS","METERS"), ("KILOMETERS","KILOMETERS"), ("VOLT","VOLT"), ("Number", "Number"))
#ITEM #ITEM
ITEM_CHOICES = get_instances("SAO#Item") #ITEM_CHOICES = get_instances("SAO#Item")
ITEM_CLASSES_COMMENTS = get_dmo_classes_and_comment("SAO#Item") #ITEM_CLASSES_COMMENTS = get_dmo_classes_and_comment("SAO#Item")
ITEM_SUBCLASSES_COMMENTS = get_dmo_classes_of_classes_and_comment("SAO#Item") #ITEM_SUBCLASSES_COMMENTS = get_dmo_classes_of_classes_and_comment("SAO#Item")
ITEM_INSTANCES_COMMENTS = get_dmo_instance_and_comment("SAO#Item") #ITEM_INSTANCES_COMMENTS = get_dmo_instance_and_comment("SAO#Item")
# #
#Interface #Interface
INTERFACE_CHOICES = get_instances("SAO#Interface") #INTERFACE_CHOICES = get_instances("SAO#Interface")
INTERFACE_CLASSES_COMMENTS = get_dmo_classes_and_comment("SAO#Interface") #INTERFACE_CLASSES_COMMENTS = get_dmo_classes_and_comment("SAO#Interface")
INTERFACE_SUBCLASSES_COMMENTS = get_dmo_classes_of_classes_and_comment("SAO#Interface") #INTERFACE_SUBCLASSES_COMMENTS = get_dmo_classes_of_classes_and_comment("SAO#Interface")
INTERFACE_INSTANCES_COMMENTS = get_dmo_instance_and_comment("SAO#Interface") #INTERFACE_INSTANCES_COMMENTS = get_dmo_instance_and_comment("SAO#Interface")
# #
#Connection #Connection
CONNECTION_CHOICES = get_instances("SAO#Connection") #CONNECTION_CHOICES = get_instances("SAO#Connection")
CONNECTION_CLASSES_COMMENTS = get_dmo_classes_and_comment("SAO#Connection") #CONNECTION_CLASSES_COMMENTS = get_dmo_classes_and_comment("SAO#Connection")
CONNECTION_SUBCLASSES_COMMENTS = get_dmo_classes_of_classes_and_comment("SAO#Connection") #CONNECTION_SUBCLASSES_COMMENTS = get_dmo_classes_of_classes_and_comment("SAO#Connection")
CONNECTION_INSTANCES_COMMENTS = get_dmo_instance_and_comment("SAO#Connection") #CONNECTION_INSTANCES_COMMENTS = get_dmo_instance_and_comment("SAO#Connection")
# #
#Flow #Flow
FLOW_CHOICES = get_instances("SAO#Flow") #FLOW_CHOICES = get_instances("SAO#Flow")
FLOW_CLASSES_COMMENTS = get_dmo_classes_and_comment("SAO#Flow") #FLOW_CLASSES_COMMENTS = get_dmo_classes_and_comment("SAO#Flow")
FLOW_SUBCLASSES_COMMENTS = get_dmo_classes_of_classes_and_comment("SAO#Flow") #FLOW_SUBCLASSES_COMMENTS = get_dmo_classes_of_classes_and_comment("SAO#Flow")
FLOW_INSTANCES_COMMENTS = get_dmo_instance_and_comment("SAO#Flow") #FLOW_INSTANCES_COMMENTS = get_dmo_instance_and_comment("SAO#Flow")
# #
#State #State
STATE_CHOICES = get_instances("SAO#State") #STATE_CHOICES = get_instances("SAO#State")
STATE_CLASSES_COMMENTS = get_dmo_classes_and_comment("SAO#State") #STATE_CLASSES_COMMENTS = get_dmo_classes_and_comment("SAO#State")
STATE_SUBCLASSES_COMMENTS = get_dmo_classes_of_classes_and_comment("SAO#State") #STATE_SUBCLASSES_COMMENTS = get_dmo_classes_of_classes_and_comment("SAO#State")
STATE_INSTANCES_COMMENTS = get_dmo_instance_and_comment("SAO#State") #STATE_INSTANCES_COMMENTS = get_dmo_instance_and_comment("SAO#State")
#State Choices #State Choices
STATE_SET_CHOICES = get_instances("SAO#StateSet") #STATE_SET_CHOICES = get_instances("SAO#StateSet")
STATECHOICES_CLASSES_COMMENTS = get_dmo_classes_and_comment("SAO#StateSet") #STATECHOICES_CLASSES_COMMENTS = get_dmo_classes_and_comment("SAO#StateSet")
# #
#State Values #State Values
STATE_VALUE_CHOICES =get_instances("SAO#StateValue") #STATE_VALUE_CHOICES =get_instances("SAO#StateValue")
STATEVALUES_CLASSES_COMMENTS = get_dmo_classes_and_comment("SAO#StateValue") #STATEVALUES_CLASSES_COMMENTS = get_dmo_classes_and_comment("SAO#StateValue")
# #
#VERB_CHOICES = get_verb_instances("LO#Verb") #VERB_CHOICES = get_verb_instances("LO#Verb")
...@@ -116,23 +116,23 @@ class Main(models.Model): ...@@ -116,23 +116,23 @@ class Main(models.Model):
boilerplate_of_main = models.ForeignKey('reqtool.Boilerplate', related_name='main_boilerplate', on_delete=models.CASCADE) boilerplate_of_main = models.ForeignKey('reqtool.Boilerplate', related_name='main_boilerplate', on_delete=models.CASCADE)
main_owner = models.ForeignKey(User, related_name='main_owner', on_delete=models.CASCADE) main_owner = models.ForeignKey(User, related_name='main_owner', on_delete=models.CASCADE)
#Subject #Subject
sys_fun_inter = models.CharField(choices=SYSTEM_CHOICES + FUNCTION_CHOICES + INTERFACE_CHOICES, max_length=100) sys_fun_inter = models.CharField(max_length=100)
#Between Subject - Verb #Between Subject - Verb
state_item_before_verb = models.CharField(choices=STATE_CHOICES + ITEM_CHOICES, max_length=100, blank=True) state_item_before_verb = models.CharField(max_length=100, blank=True)
statevalue_before_verb = models.CharField(choices=STATE_VALUE_CHOICES, max_length=100, blank=True) statevalue_before_verb = models.CharField(max_length=100, blank=True)
#Verb #Verb
shall = models.CharField(choices=SHALL_CHOICES, max_length=100) shall = models.CharField(max_length=100)
verb = models.CharField(choices=VERB_CHOICES, max_length=100) verb = models.CharField(max_length=100)
#Between Verb - Object #Between Verb - Object
quantifier = models.CharField(choices=QUANTIFIER_CHOICES, max_length=100, blank=True) quantifier = models.CharField(max_length=100, blank=True)
numerical = models.CharField(blank=True, null=True, max_length=10) numerical = models.CharField(blank=True, null=True, max_length=10)
mumerical_units = models.CharField(choices=NUMBER_UNITS_CHOICES, max_length=100, blank=True) mumerical_units = models.CharField(max_length=100, blank=True)
#Οbject #Οbject
flow_function_interface_item_system_state_stateset = models.CharField(choices=FLOW_CHOICES + FUNCTION_CHOICES + INTERFACE_CHOICES + ITEM_CHOICES + SYSTEM_CHOICES +STATE_CHOICES + STATE_SET_CHOICES, max_length=100) flow_function_interface_item_system_state_stateset = models.CharField( max_length=100)
#last definitions #last definitions
statevalue_system_connection_stateset = models.CharField(choices=STATE_VALUE_CHOICES + SYSTEM_CHOICES + CONNECTION_CHOICES + STATE_SET_CHOICES, max_length=100, blank=True) statevalue_system_connection_stateset = models.CharField(max_length=100, blank=True)
#ID [M1-M16] #ID [M1-M16]
main_choices = models.CharField(choices=MAIN_CHOICES, max_length=100) main_choices = models.CharField(max_length=100, blank=True)
class Meta: class Meta:
ordering = ['boilerplate_of_main'] ordering = ['boilerplate_of_main']
......
...@@ -13,7 +13,7 @@ from pygments import highlight ...@@ -13,7 +13,7 @@ from pygments import highlight
#get prefix syntax from the Onotlogy# #get prefix syntax from the Onotlogy#
#print(get_prefix_new_syntax()) #print(get_prefix_new_syntax())
PREFIX_SYNTAX = get_prefix_syntax() #PREFIX_SYNTAX = get_prefix_syntax()
SIMPLE_PREFIX_CHOICES = ( ("",""), SIMPLE_PREFIX_CHOICES = ( ("",""),
...@@ -32,8 +32,9 @@ LOGICAL_EXPRESSION = ( ("",""), ...@@ -32,8 +32,9 @@ LOGICAL_EXPRESSION = ( ("",""),
("occuring functionality", "occuring functionality") ("occuring functionality", "occuring functionality")
) )
#Need fixing
#VERB_CHOICES_PREFIX = ( ("",""))
VERB_CHOICES_PREFIX = get_prefix_verbs()
#Must read this info from the Ontology #Must read this info from the Ontology
...@@ -73,23 +74,33 @@ def create_extra_prefix(instance, now_prefix): ...@@ -73,23 +74,33 @@ def create_extra_prefix(instance, now_prefix):
def create_infer_result(instance): def create_infer_result(instance):
infer = InferenceResults(owner_infer= instance.boilerplate_owner, infer_group_of_boilerplate = instance) infer = InferenceResults(owner_infer= instance.boilerplate_owner, infer_group_of_boilerplate = instance, ontology_file=instance.ontology_file)
infer.save() infer.save()
#Here we have to give and the ontology file of the Boilerplate Group to get the current instances #Here we have to give and the ontology file of the Boilerplate Group to get the current instances
def initialize_instances(instance): def initialize_instances(instance):
classes_inctances = BoilerplateGroupClassesInstances ( classes_instances_owner= instance.boilerplate_owner, classes_instances_group_of_boilerplate = instance, classes_inctances = BoilerplateGroupClassesInstances ( classes_instances_owner= instance.boilerplate_owner, classes_instances_group_of_boilerplate = instance,
prefix_choices = json.dumps(PREFIX_CHOICES), prefix_logcon_choices =json.dumps(LOGIC_CONNECTIVE), prefix_verb_choices =json.dumps(STATE_CHOICES + VERB_CHOICES_PREFIX), ontology_file=instance.ontology_file )
main_class_choices =json.dumps(MAIN_CHOICES), system_choices = json.dumps(SYSTEM_CHOICES), function_choices =json.dumps(FUNCTION_CHOICES),
quantifier_choices=json.dumps(QUANTIFIER_CHOICES), number_unit_choices=json.dumps(NUMBER_UNITS_CHOICES), item_choices=json.dumps(ITEM_CHOICES),
inteface_choices=json.dumps(INTERFACE_CHOICES), connection_choices=json.dumps(CONNECTION_CHOICES), flow_choices=json.dumps(FLOW_CHOICES),
state_choices=json.dumps(STATE_CHOICES),state_set_choices=json.dumps(STATE_SET_CHOICES), state_value_choices=json.dumps(STATE_VALUE_CHOICES),
main_verb_choices=json.dumps(VERB_CHOICES), numerical_affirmative_choices=json.dumps(NUMERICAL_AFFIRMATIVE_CHOICES),
suffix_choices=json.dumps(S_CHOICES) )
classes_inctances.save() classes_inctances.save()
dict = BoilerplateGroupDictionary( classes_instances_owner_dic= instance.boilerplate_owner, classes_instances_group_of_boilerplate_dic = instance,
ontology_file_dic=instance.ontology_file )
dict.save()
'''Update instaces of the ontology after the inferencing''' '''Update instaces of the ontology after the inferencing'''
def update_instances(instance): def update_instances(instance):
g = Graph()
g.load(instance.ontology_file, format="turtle")
#PREFIX_SYNTAX = get_prefix_syntax(g)
VERB_CHOICES_PREFIX = get_prefix_verbs(g)
SYSTEM_CHOICES = get_instances_g("SAO#System",g)
FUNCTION_CHOICES = get_instances_g("SAO#Function",g)
ITEM_CHOICES = get_instances_g("SAO#Item",g)
INTERFACE_CHOICES = get_instances_g("SAO#Interface",g)
CONNECTION_CHOICES = get_instances_g("SAO#Connection",g)
FLOW_CHOICES = get_instances_g("SAO#Flow",g)
STATE_CHOICES = get_instances_g("SAO#State",g)
STATE_SET_CHOICES = get_instances_g("SAO#StateSet",g)
STATE_VALUE_CHOICES =get_instances_g("SAO#StateValue",g)
BoilerplateGroupClassesInstances.objects.filter(classes_instances_owner= instance.owner_infer, classes_instances_group_of_boilerplate = instance.infer_group_of_boilerplate).update( BoilerplateGroupClassesInstances.objects.filter(classes_instances_owner= instance.owner_infer, classes_instances_group_of_boilerplate = instance.infer_group_of_boilerplate).update(
prefix_choices = json.dumps(PREFIX_CHOICES), prefix_logcon_choices =json.dumps(LOGIC_CONNECTIVE), prefix_verb_choices =json.dumps(STATE_CHOICES + VERB_CHOICES_PREFIX), prefix_choices = json.dumps(PREFIX_CHOICES), prefix_logcon_choices =json.dumps(LOGIC_CONNECTIVE), prefix_verb_choices =json.dumps(STATE_CHOICES + VERB_CHOICES_PREFIX),
main_class_choices =json.dumps(MAIN_CHOICES), system_choices = json.dumps(SYSTEM_CHOICES), function_choices =json.dumps(FUNCTION_CHOICES), main_class_choices =json.dumps(MAIN_CHOICES), system_choices = json.dumps(SYSTEM_CHOICES), function_choices =json.dumps(FUNCTION_CHOICES),
...@@ -98,6 +109,12 @@ def update_instances(instance): ...@@ -98,6 +109,12 @@ def update_instances(instance):
state_choices=json.dumps(STATE_CHOICES),state_set_choices=json.dumps(STATE_SET_CHOICES), state_value_choices=json.dumps(STATE_VALUE_CHOICES), state_choices=json.dumps(STATE_CHOICES),state_set_choices=json.dumps(STATE_SET_CHOICES), state_value_choices=json.dumps(STATE_VALUE_CHOICES),
main_verb_choices=json.dumps(VERB_CHOICES), numerical_affirmative_choices=json.dumps(NUMERICAL_AFFIRMATIVE_CHOICES), main_verb_choices=json.dumps(VERB_CHOICES), numerical_affirmative_choices=json.dumps(NUMERICAL_AFFIRMATIVE_CHOICES),
suffix_choices=json.dumps(S_CHOICES) ) suffix_choices=json.dumps(S_CHOICES) )
Dict_list=[]
sao_names=['SAO#System', 'SAO#Function', 'SAO#Item', 'SAO#Interface', 'SAO#Connection', 'SAO#Flow', 'SAO#State', 'SAO#StateSet', 'SAO#StateValue']
for i in sao_names:
Dict_list.append(get_dmo_classes_and_comment(i, g))
#Dictionary_Data_list.append
BoilerplateGroupDictionary.objects.filter(classes_instances_owner_dic= instance.owner_infer, classes_instances_group_of_boilerplate_dic = instance.infer_group_of_boilerplate).update(Dictionary_Data =Dict_list)
...@@ -105,6 +122,7 @@ def update_instances(instance): ...@@ -105,6 +122,7 @@ def update_instances(instance):
class BoilerplateGroup(models.Model): class BoilerplateGroup(models.Model):
boilerplate_owner = models.ForeignKey(User, related_name='boilerplate_group_owner', on_delete=models.CASCADE) boilerplate_owner = models.ForeignKey(User, related_name='boilerplate_group_owner', on_delete=models.CASCADE)
#add Boilerplate path, so each Boilerplate Group can hace it's own Ontology file #add Boilerplate path, so each Boilerplate Group can hace it's own Ontology file
ontology_file = models.CharField(default="../../Ontologies/Autonomy_v1.ttl", max_length=100, blank=True)
title_bgroup = models.CharField(max_length=100, unique=True) title_bgroup = models.CharField(max_length=100, unique=True)
description = models.CharField(max_length=500) description = models.CharField(max_length=500)
...@@ -173,18 +191,18 @@ class PrefixGroup(models.Model): ...@@ -173,18 +191,18 @@ class PrefixGroup(models.Model):
class Prefix(models.Model): class Prefix(models.Model):
prefixgroup = models.ForeignKey(PrefixGroup, related_name='prefix', on_delete=models.CASCADE) prefixgroup = models.ForeignKey(PrefixGroup, related_name='prefix', on_delete=models.CASCADE)
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(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(max_length=100)
state_or_verb = models.CharField(choices=STATE_CHOICES + VERB_CHOICES_PREFIX, max_length=100) state_or_verb = models.CharField(max_length=100)
#occuring functionality #occuring functionality
item_function_flow_statevalue = models.CharField(choices=ITEM_CHOICES + FLOW_CHOICES + FUNCTION_CHOICES + STATE_VALUE_CHOICES, max_length=100) item_function_flow_statevalue = models.CharField(max_length=100)
#state value constraint OR occuring functionality #state value constraint OR occuring functionality
logical_expression = models.CharField(choices=LOGICAL_EXPRESSION, max_length=100, blank=True) logical_expression = models.CharField(max_length=100, blank=True)
#Logic connectivity Prefix1 (and/or/xor) Prefix2 #Logic connectivity Prefix1 (and/or/xor) Prefix2
logic_connective = models.CharField(choices=LOGIC_CONNECTIVE, default='', max_length=100, blank=True) logic_connective = models.CharField(max_length=100, blank=True)
#Prefix value P1/P2/P3 #Prefix value P1/P2/P3
simple_prefix = models.CharField(choices=SIMPLE_PREFIX_CHOICES, max_length=100) simple_prefix = models.CharField(max_length=100, blank=True)
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
...@@ -226,6 +244,7 @@ class BoilerplateData(models.Model): ...@@ -226,6 +244,7 @@ class BoilerplateData(models.Model):
class InferenceResults(models.Model): class InferenceResults(models.Model):
owner_infer = models.ForeignKey(User, related_name='owner_infer', on_delete=models.CASCADE) owner_infer = models.ForeignKey(User, related_name='owner_infer', on_delete=models.CASCADE)
infer_group_of_boilerplate = models.ForeignKey(BoilerplateGroup, related_name='infer_owner_of_boilerplate', on_delete=models.CASCADE) infer_group_of_boilerplate = models.ForeignKey(BoilerplateGroup, related_name='infer_owner_of_boilerplate', on_delete=models.CASCADE)
ontology_file = models.CharField(max_length=100, blank=True)
inference_data = models.CharField(default="", max_length=1000000, blank=True) inference_data = models.CharField(default="", max_length=1000000, blank=True)
def save(self, **kwargs): def save(self, **kwargs):
...@@ -263,4 +282,8 @@ class BoilerplateGroupClassesInstances(models.Model): ...@@ -263,4 +282,8 @@ class BoilerplateGroupClassesInstances(models.Model):
suffix_choices = JSONField() suffix_choices = JSONField()
class BoilerplateGroupDictionary(models.Model):
classes_instances_group_of_boilerplate_dic = models.ForeignKey(BoilerplateGroup, related_name='classes_instances_owner_of_boilerplate_dic', on_delete=models.CASCADE)
classes_instances_owner_dic = models.ForeignKey(User, related_name='classes_instances_owner_dic', on_delete=models.CASCADE)
ontology_file_dic = models.CharField(default="", max_length=100, blank=True)
Dictionary_Data = JSONField()
from rest_framework import serializers from rest_framework import serializers
from reqman.apps.reqtool.models.requirements import Prefix, Boilerplate, BoilerplateData, BoilerplateGroup, InferenceResults, BoilerplateGroupClassesInstances from reqman.apps.reqtool.models.requirements import BoilerplateGroupDictionary, Prefix, Boilerplate, BoilerplateData, BoilerplateGroup, InferenceResults, BoilerplateGroupClassesInstances
class BoilerplateSerializer(serializers.ModelSerializer): class BoilerplateSerializer(serializers.ModelSerializer):
...@@ -43,4 +43,9 @@ class BoilerplateGroupClassesInstancesSerializer(serializers.ModelSerializer): ...@@ -43,4 +43,9 @@ class BoilerplateGroupClassesInstancesSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = BoilerplateGroupClassesInstances model = BoilerplateGroupClassesInstances
fields = '__all__' fields = '__all__'
class BoilerplateGroupDictionarySerializer(serializers.ModelSerializer):
classes_instances_owner_dic = serializers.ReadOnlyField(source='owner.username')
class Meta:
model = BoilerplateGroupDictionary
fields = '__all__'
...@@ -3,16 +3,15 @@ from rdflib import Graph, BNode ...@@ -3,16 +3,15 @@ from rdflib import Graph, BNode
from rdflib.namespace import RDFS from rdflib.namespace import RDFS
from rdflib import ConjunctiveGraph, URIRef, RDFS, RDF, Namespace 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
#HERE #HERE
#Ontology_file = "../../Ontologies/Autonomy_v1.ttl" #Ontology_file = "../../Ontologies/Autonomy_v1.ttl"
Ontology_file = "../../Ontologies/2022_AOCS.ttl" 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() prefix_syntax = get_prefix_syntax(g)
main_syntax = get_main_sytax_inference() main_syntax = get_main_sytax_inference()
...@@ -23,6 +22,8 @@ def getclassofmain(main): ...@@ -23,6 +22,8 @@ def getclassofmain(main):
return(findclassofmain(main)) return(findclassofmain(main))
def getinstancefile(data): def getinstancefile(data):
datam = data.split(":")
out_list = get_file_and_instances('SAO#'+ datam[0].strip())
for j in range(0,(len(out_list)-1),2): for j in range(0,(len(out_list)-1),2):
if out_list[j]==data: if out_list[j]==data:
splitter = out_list[j].split(" : ") splitter = out_list[j].split(" : ")
...@@ -31,7 +32,7 @@ def getinstancefile(data): ...@@ -31,7 +32,7 @@ def getinstancefile(data):
return instance_file, splitter return instance_file, splitter
def inferencing(project, boilerlate, prefix, main, suffix): def inferencing(ontfile, project, boilerlate, prefix, main, suffix):
metrics = {} metrics = {}
listofboil = [] listofboil = []
listofprefix = [] listofprefix = []
...@@ -48,8 +49,9 @@ def inferencing(project, boilerlate, prefix, main, suffix): ...@@ -48,8 +49,9 @@ def inferencing(project, 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)
ontology_with_new_req = exportboiltottl(project, listofprefix, listofboil, listofmain, listofsuffix) ontology_with_new_req = exportboiltottl(ontfile, project, listofprefix, listofboil, listofmain, listofsuffix)
infer_result = shacl(ontology_with_new_req) infer_result = shacl(ontology_with_new_req)
ontology_with_new_req_and_infer = ontology_with_new_req+"infer.ttl"
#find in which metrics the requirements belongs e.g. title:REQ-1 is only an Incomplete req (and Ambiguous req), #find in which metrics the requirements belongs e.g. title:REQ-1 is only an Incomplete req (and Ambiguous req),
# so -> 'REQ-1' : [Incomplete] ('REQ-1' : [Incomplete, Ambiguous]) # so -> 'REQ-1' : [Incomplete] ('REQ-1' : [Incomplete, Ambiguous])
for met in infer_result: for met in infer_result:
...@@ -57,24 +59,29 @@ def inferencing(project, boilerlate, prefix, main, suffix): ...@@ -57,24 +59,29 @@ def inferencing(project, boilerlate, prefix, main, suffix):
if title in infer_result[met]: if title in infer_result[met]:
metrics[title].append(met) metrics[title].append(met)
metrics.update(infer_result) metrics.update(infer_result)
return (metrics, ontology_with_new_req) return (metrics, ontology_with_new_req_and_infer)
def exportboiltottl(project, prefix, boilerplate, main, suffix): def exportboiltottl(ontfile,project, prefix, boilerplate, main, suffix):
''' Export boilerplate to ttl file and return the file path''' ''' Export boilerplate to ttl file and return the file path'''
#print(out_list) #A list with the values and the file that is the instance
file_name = project.replace('/', '')
if (os.path.exists("../../Ontologies/"+file_name+"/") == False):
os.mkdir("../../Ontologies/"+file_name)
save_path = "../../Ontologies/"+file_name+"/"
completeName = os.path.join(save_path, file_name)
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#")
sao = URIRef("http://delab.csd.auth.gr/ontologies/2018/SAO#") sao = URIRef("http://delab.csd.auth.gr/ontologies/2018/SAO#")
rbo = URIRef("http://delab.csd.auth.gr/ontologies/2018/RBO#") rbo = URIRef("http://delab.csd.auth.gr/ontologies/2018/RBO#")
lo = URIRef("http://delab.csd.auth.gr/ontologies/2018/LO-instances#") lo = URIRef("http://delab.csd.auth.gr/ontologies/2018/LO-instances#")
g = Graph() g = Graph()
g.load(Ontology_file, format="turtle") #find the ontology to load
file_name = project.replace('/', '')
save_path = "../../Ontologies/"+file_name+"/"
if (os.path.exists("../../Ontologies/"+file_name+"/") == False):
os.mkdir("../../Ontologies/"+file_name)
completeName = os.path.join(save_path, file_name)
g.load('../../Ontologies/'+ontfile, format="turtle")
else :
g.load(ontfile, format="turtle")
#remove the requirements from the RDO-instances
previous_req = URIRef("http://delab.csd.auth.gr/ontologies/2018/RDO-instances")
g.remove((previous_req, None, None))
for i in range(len(boilerplate)): for i in range(len(boilerplate)):
title = boilerplate[i][0]['title'] title = boilerplate[i][0]['title']
g.add((per_instances + title, RDF.type, rdo + 'Requirement')) g.add((per_instances + title, RDF.type, rdo + 'Requirement'))
...@@ -134,6 +141,7 @@ def exportboiltottl(project, prefix, boilerplate, main, suffix): ...@@ -134,6 +141,7 @@ def exportboiltottl(project, prefix, boilerplate, main, suffix):
#Need S3 #Need S3
g.add((per_instances+(title+"_"+ suffix[i][0]['suffix_choices']), RDF.type, URIRef(rbo+ suffix[i][0]['suffix_choices']))) g.add((per_instances+(title+"_"+ suffix[i][0]['suffix_choices']), RDF.type, URIRef(rbo+ suffix[i][0]['suffix_choices'])))
#g.remove((per_instances + title, None, None))
g.serialize(destination=save_path+file_name+'.ttl', format='turtle') g.serialize(destination=save_path+file_name+'.ttl', format='turtle')
return (save_path+file_name) return (save_path+file_name)
...@@ -202,65 +210,20 @@ def findclassofmain(listofmain): ...@@ -202,65 +210,20 @@ def findclassofmain(listofmain):
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['verb'].rsplit(' : ', 1) currentverb = listofmain['verb'].rsplit(' : ', 1)
currentsubject = listofmain['sys_fun_inter'] currentsubject = listofmain['sys_fun_inter'].rsplit(' : ')
currentattr = listofmain['flow_function_interface_item_system_state_stateset'] currentattr = listofmain['flow_function_interface_item_system_state_stateset'].rsplit(' : ')
for verbmain in verbsmain: for verbmain in verbsmain:
flag = 0 flag = 0
if (verbmain.upper() == currentverb[len(currentverb)-1].upper() ): if (verbmain.upper() == currentverb[len(currentverb)-1].upper() ):
for submain in subsmain: for submain in subsmain:
flag = 0 flag = 0
if submain == "System": if submain == currentsubject[0].strip():
for sys in SYSTEM_CHOICES: flag = 1
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 : if flag == 1 :
for attrmain in attrsmain: for attrmain in attrsmain:
if attrmain == "Flow": if attrmain == currentattr[0].strip():
for sys in FLOW_CHOICES: classlist.append('M'+str(i+1))
if sys[0] == currentattr: return(classlist)
classlist.append('M'+str(i+1))
return(classlist)
if attrmain == "Item":
for sys in ITEM_CHOICES:
if sys[0] == currentattr:
classlist.append('M'+str(i+1))
return(classlist)
if attrmain == "Function":
for sys in FUNCTION_CHOICES:
if sys[0] == currentattr:
classlist.append('M'+str(i+1))
return(classlist)
if attrmain == "System":
for sys in SYSTEM_CHOICES:
if sys[0] == currentattr:
classlist.append('M'+str(i+1))
return(classlist)
if attrmain == "Interface":
for sys in INTERFACE_CHOICES:
if sys[0] == currentattr:
classlist.append('M'+str(i+1))
return(classlist)
if attrmain == "State":
for sys in (STATE_CHOICES):
if sys[0] == currentattr:
classlist.append('M'+str(i+1))
return(classlist)
if attrmain == "StateSet":
for sys in (STATE_SET_CHOICES):
if sys[0] == currentattr:
classlist.append('M'+str(i+1))
return(classlist)
classlist.append("ERROR") classlist.append("ERROR")
return classlist return classlist
......
...@@ -8,7 +8,7 @@ from rdflib import ConjunctiveGraph, URIRef, RDFS, RDF, Namespace ...@@ -8,7 +8,7 @@ from rdflib import ConjunctiveGraph, URIRef, RDFS, RDF, Namespace
#Ontology_file = "../../Ontologies/Mokos_18_1_7_47.ttl" #Ontology_file = "../../Ontologies/Mokos_18_1_7_47.ttl"
#Ontology_file = "../../Ontologies/Autonomy_v1.ttl" #Ontology_file = "../../Ontologies/Autonomy_v1.ttl"
Ontology_file = "../../Ontologies/2022_AOCS.ttl" Ontology_file = "../../Ontologies/Autonomy_v1.ttl"
subClass_instances = "../../Ontologies/instances_subclass.txt" subClass_instances = "../../Ontologies/instances_subclass.txt"
...@@ -39,11 +39,11 @@ def find_subclass_domain_range(): ...@@ -39,11 +39,11 @@ def find_subclass_domain_range():
def findsubclass(): def findsubclass():
file2 = open(subClass_instances, "w+") subclasslist = []
for subj, obj in g.subject_objects(predicate=RDFS.subClassOf): for subj, obj in g.subject_objects(predicate=RDFS.subClassOf):
subClass = subj + "$"+ obj + "\n" subClass = subj + "$"+ obj + "\n"
file2.write(subClass) subclasslist.append(subClass)
return subclasslist
def get_i_instances(keyword): def get_i_instances(keyword):
...@@ -96,16 +96,52 @@ def get_verb_file_and_instances(keyword): ...@@ -96,16 +96,52 @@ def get_verb_file_and_instances(keyword):
'''Get Instaces - return tuple''' '''Get Instaces - return tuple'''
def get_instances(keyword): def get_instances(keyword):
get_file_and_instances(keyword) #get_file_and_instances(keyword)
keywordspl = keyword.split("#") keywordspl = keyword.split("#")
in_list = [keywordspl[len(keywordspl)-1]] in_list = [keywordspl[len(keywordspl)-1]]
out_list = [] out_list = []
with open('../../Ontologies/instances.txt') as f: #with open('../../Ontologies/instances.txt') as f:
for data in f: # for data in f:
if (data.strip()).endswith(keyword): # if (data.strip()).endswith(keyword):
spliter_1 = data.split('$') # spliter_1 = data.split('$')
spliter_2 = spliter_1[0].split("#") # spliter_2 = spliter_1[0].split("#")
in_list.append(spliter_2[len(spliter_2) - 1]) # in_list.append(spliter_2[len(spliter_2) - 1])
for extra in in_list:
for uri in list_of_DSO:
per = URIRef(uri +extra)
for s, p, o in g.triples((None, RDFS.subClassOf, per)): #subClassOf
spl = s.split("#")
in_list.append(spl[len(spl) - 1])
for extra in in_list:
for uri in list_of_DSO:
p = URIRef(uri +extra)
for s, p, o in g.triples((None, RDF.type, p)):
spl = s.split("#")
uri = spl[len(spl) - 2].split("/")
out_list.append(spl[len(spl) - 1])
#new code
out_list.append(extra)
return tuple((str(keywordspl[len(keywordspl)-1]+" : "+out_list[n+1]+" : "+out_list[n]), str(keywordspl[len(keywordspl)-1]+" : "+out_list[n+1]+" : "+out_list[n]) ) for n in range(0, len(out_list), 2))
# A list with the values and the file that is the instance
out_list = []
# A dict with all the info of classes, subclasses and instances
info_dict = {}
'''Get Instaces - return tuple'''
def get_instances_g(keyword, g):
#get_file_and_instances(keyword)
keywordspl = keyword.split("#")
in_list = [keywordspl[len(keywordspl)-1]]
out_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])
for extra in in_list: for extra in in_list:
for uri in list_of_DSO: for uri in list_of_DSO:
per = URIRef(uri +extra) per = URIRef(uri +extra)
...@@ -130,20 +166,17 @@ out_list = [] ...@@ -130,20 +166,17 @@ out_list = []
info_dict = {} info_dict = {}
def get_file_and_instances(keyword): def get_file_and_instances(keyword):
out_list = []
keywordspl = keyword.split("#") keywordspl = keyword.split("#")
in_list = [keywordspl[len(keywordspl)-1]] in_list = [keywordspl[len(keywordspl)-1]]
with open('../../Ontologies/instances.txt') as f: #find one layer down System: Subclass
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])
for extra in in_list: for extra in in_list:
for uri in list_of_DSO: for uri in list_of_DSO:
per = URIRef(uri +extra) per = URIRef(uri +extra)
for s, p, o in g.triples((None, RDFS.subClassOf, per)): #subClassOf for s, p, o in g.triples((None, RDFS.subClassOf, per)): #subClassOf
spl = s.split("#") spl = s.split("#")
in_list.append(spl[len(spl) - 1]) in_list.append(spl[len(spl) - 1])
#find two layer down System: Subclass : Instance
for extra in in_list: for extra in in_list:
for uri in list_of_DSO: for uri in list_of_DSO:
per = URIRef(uri +extra) per = URIRef(uri +extra)
...@@ -152,7 +185,8 @@ def get_file_and_instances(keyword): ...@@ -152,7 +185,8 @@ def get_file_and_instances(keyword):
uri = spl[len(spl) - 2].split("/") uri = spl[len(spl) - 2].split("/")
out_list.append(keywordspl[len(keywordspl)-1]+" : "+extra+" : " +spl[len(spl) - 1]) out_list.append(keywordspl[len(keywordspl)-1]+" : "+extra+" : " +spl[len(spl) - 1])
out_list.append(str(spl[len(spl) - 2])) out_list.append(str(spl[len(spl) - 2]))
#return out_list#tuple((out_list[i+1], out_list[i]) for i in range(0, (len(out_list) - 1), 2) ) return out_list
#Instances and Comments #Instances and Comments
def get_dmo_instance_and_comment(keyword): def get_dmo_instance_and_comment(keyword):
...@@ -193,7 +227,7 @@ def get_dmo_instance_and_comment(keyword): ...@@ -193,7 +227,7 @@ def get_dmo_instance_and_comment(keyword):
#Classes and Comments #Classes and Comments
def get_dmo_classes_and_comment(keyword): def get_dmo_classes_and_comment(keyword, g):
dmo_dic = {} dmo_dic = {}
dic_list = [] dic_list = []
dmo_dic_in = {} dmo_dic_in = {}
...@@ -281,19 +315,19 @@ def get_dmo_classes_and_comment(keyword): ...@@ -281,19 +315,19 @@ def get_dmo_classes_and_comment(keyword):
dic_list.append(dmo_dic) dic_list.append(dmo_dic)
if out_list_com: if out_list_com:
Dictionary_Data = { "Name":section, "TheClasses" : dic_list, "GeneralInstances": dic_list_in} Dictionary_Data = { "Name":section, "TheClasses" : dic_list, "GeneralInstances": dic_list_in}
Dictionary_Data_list.append(Dictionary_Data) return Dictionary_Data
return dic_list #return dic_list
else: else:
if dic_list_backup: if dic_list_backup:
Dictionary_Data = { "Name":section, "TheClasses" : dic_list_backup, "GeneralInstances": dic_list_in} Dictionary_Data = { "Name":section, "TheClasses" : dic_list_backup, "GeneralInstances": dic_list_in}
Dictionary_Data_list.append(Dictionary_Data) return Dictionary_Data
return dic_list_backup #return dic_list_backup
else: else:
dmo_dic_backup = {"Class": " ", "Comment":" "} dmo_dic_backup = {"Class": " ", "Comment":" "}
dic_list_backup.append(dmo_dic_backup) dic_list_backup.append(dmo_dic_backup)
Dictionary_Data = { "Name":section, "TheClasses" : dic_list_backup, "GeneralInstances": dic_list_in} Dictionary_Data = { "Name":section, "TheClasses" : dic_list_backup, "GeneralInstances": dic_list_in}
Dictionary_Data_list.append(Dictionary_Data) return Dictionary_Data
return dic_list_backup #return dic_list_backup
#Classes of classes and Comments #Classes of classes and Comments
def get_dmo_classes_of_classes_and_comment(keyword): def get_dmo_classes_of_classes_and_comment(keyword):
...@@ -330,14 +364,13 @@ def get_dmo_classes_of_classes_and_comment(keyword): ...@@ -330,14 +364,13 @@ def get_dmo_classes_of_classes_and_comment(keyword):
'''Get Instaces - return list''' '''Get Instaces - return list'''
def get_instances_list(keyword): def get_instances_list(keyword):
findsubclass() f = findsubclass()
an_list=[] an_list=[]
with open(subClass_instances) as f: for data in f:
for data in f: if (data.strip()).endswith(keyword):
if (data.strip()).endswith(keyword): spliter_1 = data.split('$')
spliter_1 = data.split('$') spliter_2 = spliter_1[0].split("#")
spliter_2 = spliter_1[0].split("#") an_list.append(spliter_2[len(spliter_2) - 1])
an_list.append(spliter_2[len(spliter_2) - 1])
return an_list return an_list
...@@ -502,7 +535,7 @@ def get_main_sytax_inference(): ...@@ -502,7 +535,7 @@ def get_main_sytax_inference():
main_dict[main]["Quantifier"] = check_quantifier(bnodes_uriref) main_dict[main]["Quantifier"] = check_quantifier(bnodes_uriref)
main_dict[main]["Attributes"] = get_attribute(bnodes_uriref, main_dict[main]["Subject"], main_dict[main]["Related_to_Subject"], main_dict[main]["Verbs"]) main_dict[main]["Attributes"] = get_attribute(bnodes_uriref, main_dict[main]["Subject"], main_dict[main]["Related_to_Subject"], main_dict[main]["Verbs"])
print( main_dict[main]["Subject"]) #print( main_dict[main]["Subject"])
return main_dict return main_dict
...@@ -546,7 +579,7 @@ def get_main_sytax(): ...@@ -546,7 +579,7 @@ def get_main_sytax():
'''Find Prefix syntax - return a dict with the syntax''' '''Find Prefix syntax - return a dict with the syntax'''
def get_prefix_syntax(): def get_prefix_syntax(g):
prefix_dict={} prefix_dict={}
prefix_list = [] prefix_list = []
get_prefix = get_instances_list("RBO#Prefix") get_prefix = get_instances_list("RBO#Prefix")
...@@ -621,7 +654,7 @@ def get_prefix_syntax(): ...@@ -621,7 +654,7 @@ def get_prefix_syntax():
'''Return Verb list Of Prefixes''' '''Return Verb list Of Prefixes'''
def get_prefix_verbs(): def get_prefix_verbs(g):
prefix_dict={} prefix_dict={}
prefix_list = [] prefix_list = []
verblist =[] verblist =[]
......
...@@ -34,58 +34,15 @@ urlpatterns = [ ...@@ -34,58 +34,15 @@ urlpatterns = [
#MAIN CHOICES DATA #MAIN CHOICES DATA
path('groupboilerplates/<int:groupboil>/main/choices/', main_req_views.MainChoicesViewSet.as_view(), name='mainchoices'), path('groupboilerplates/<int:groupboil>/main/choices/', main_req_views.MainChoicesViewSet.as_view(), name='mainchoices'),
path('main/choices/subject/', main_req_views.SysFunIntChoicesViewSet.as_view(), name='mainsubject'),
path('main/choices/stateitem/', main_req_views.StatItemChoicesViewSet.as_view(), name='mainstateitem'),
path('main/choices/statevalue/', main_req_views.StatevalueChoicesViewSet.as_view(), name='mainstatevalue'),
path('main/choices/shall/', main_req_views.ShallChoicesViewSet.as_view(), name='mainshall'), path('main/choices/shall/', main_req_views.ShallChoicesViewSet.as_view(), name='mainshall'),
path('main/choices/verb/', main_req_views.VerbChoicesViewSet.as_view(), name='mainverb'),
path('main/choices/quantifier/', main_req_views.QuantChoicesViewSet.as_view(), name='mainquantifier'),
path('main/choices/numunit/', main_req_views.NumUnitChoicesViewSet.as_view(), name='mainnumunit'),
path('main/choices/fifuintsysstatset/', main_req_views.FlFuIntItSysStatSetChoicesViewSet.as_view(), name='mainfifuintsysstatset'),
path('main/choices/stsysconset/', main_req_views.StaSysConSetChoicesViewSet.as_view(), name='mainstsysconset'),
#SUFFIX CHOICES DATA #SUFFIX CHOICES DATA
path('suffix/choices/suffix/', suffix_req_views.SuffixChoicesViewSet.as_view(), name='suffixsuffix'), path('suffix/choices/suffix/', suffix_req_views.SuffixChoicesViewSet.as_view(), name='suffixsuffix'),
path('suffix/choices/numunits/', suffix_req_views.NumChoicesViewSet.as_view(), name='suffixnum'), path('suffix/choices/numunits/', suffix_req_views.NumChoicesViewSet.as_view(), name='suffixnum'),
path('suffix/choices/flow/', suffix_req_views.FlowChoicesViewSet.as_view(), name='suffixflow'), path('suffix/choices/flow/', suffix_req_views.FlowChoicesViewSet.as_view(), name='suffixflow'),
#CLASSES System
path('class/system', main_req_views.SystemClassViewSet.as_view(), name='class_system'),
path('class/system/subclasses', main_req_views.SystemSubclasesViewSet.as_view(), name='subclass_system'),
path('class/system/instance', main_req_views.SystemInstancesViewSet.as_view(), name='instances_of_system'),
#CLASSES Function
path('class/function', main_req_views.FunctionClassViewSet.as_view(), name='class_function'),
path('class/function/subclasses', main_req_views.FunctionSubclasesViewSet.as_view(), name='subclass_function'),
path('class/function/instance', main_req_views.FunctionInstancesViewSet.as_view(), name='instances_of_function'),
#CLASSES Item
path('class/item', main_req_views.ItemClassViewSet.as_view(), name='class_item'),
path('class/item/subclasses', main_req_views.ItemSubclasesViewSet.as_view(), name='subclass_item'),
path('class/item/instance', main_req_views.ItemInstancesViewSet.as_view(), name='instances_of_item'),
#CLASSES Interface
path('class/interface', main_req_views.InterfaceClassViewSet.as_view(), name='class_interface'),
path('class/interface/subclasses', main_req_views.InterfaceSubclasesViewSet.as_view(), name='subclass_interface'),
path('class/interface/instance', main_req_views.InterfaceInstancesViewSet.as_view(), name='instances_of_interface'),
#CLASSES Connection
path('class/connection', main_req_views.ConnectionClassViewSet.as_view(), name='class_connection'),
path('class/connection/subclasses', main_req_views.ConnectionSubclasesViewSet.as_view(), name='subclass_connection'),
path('class/connection/instance', main_req_views.ConnectionInstancesViewSet.as_view(), name='instances_of_connection'),
#CLASSES Flow
path('class/flow', main_req_views.FlowClassViewSet.as_view(), name='class_flow'),
path('class/flow/subclasses', main_req_views.FlowSubclasesViewSet.as_view(), name='subclass_flow'),
path('class/flow/instance', main_req_views.FlowInstancesViewSet.as_view(), name='instances_of_flow'),
#CLASSES State
path('class/state', main_req_views.StateClassViewSet.as_view(), name='class_state'),
path('class/state/subclasses', main_req_views.StateSubclasesViewSet.as_view(), name='subclass_state'),
path('class/state/instance', main_req_views.StateInstancesViewSet.as_view(), name='instances_of_state'),
#Dictionary #Dictionary
path('dictionary/', main_req_views.DictionaryViewSet.as_view(), name='dictionary'), path('groupboilerplates/<int:groupboil>/dictionary/', main_req_views.DictionaryViewSet.as_view(), name='dictionary'),
path('mainsyntax/', main_req_views.MainSyntaxViewSet.as_view(), name='mainsyntax'), path('mainsyntax/', main_req_views.MainSyntaxViewSet.as_view(), name='mainsyntax'),
] ]
\ No newline at end of file
...@@ -6,8 +6,6 @@ from django.views.decorators.csrf import csrf_exempt ...@@ -6,8 +6,6 @@ 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 from reqman.apps.reqtool.models.requirements import Prefix, Boilerplate, BoilerplateGroup, PREFIX_CHOICES, LOGIC_CONNECTIVE
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 BoilerplateData, InferenceResults, BoilerplateGroupClassesInstances from reqman.apps.reqtool.models.requirements import BoilerplateData, InferenceResults, BoilerplateGroupClassesInstances
from reqman.apps.reqtool.rest_api.serializers.requirements import BoilerplateSerializer, PrefixSerializer, BoilerplateDataSerializer, BoilerplateGroupSerializer, InferSerializer, BoilerplateGroupClassesInstancesSerializer from reqman.apps.reqtool.rest_api.serializers.requirements import BoilerplateSerializer, PrefixSerializer, BoilerplateDataSerializer, BoilerplateGroupSerializer, InferSerializer, BoilerplateGroupClassesInstancesSerializer
...@@ -153,9 +151,21 @@ class PrefixDetailsAPIView(RetrieveUpdateDestroyAPIView): ...@@ -153,9 +151,21 @@ class PrefixDetailsAPIView(RetrieveUpdateDestroyAPIView):
ev_instance =instance['state_or_verb'].rsplit(':', 1) ev_instance =instance['state_or_verb'].rsplit(':', 1)
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 ) boildata = BoilerplateData.objects.filter(owner_data=instance['prefix_boilerplate'].owner, boilerplate_data_id = instance['prefix_boilerplate'])
boildata.update(prefix_data = pr )
#get instances of the ontology that this boilerplate belongs
data = BoilerplateGroupClassesInstances.objects.filter(classes_instances_owner= instance['prefix_boilerplate'].owner, classes_instances_group_of_boilerplate = boildata.values('group_of_boilerplate_data')[0]['group_of_boilerplate_data'])
es_data = data.values('system_choices')[0]['system_choices'] + data.values('function_choices')[0]['function_choices'] + data.values('item_choices')[0]['item_choices']
if( instance['system_fun_item'] not in es_data):
raise APIException("PREFIX : Instance of Subject does not exist")
ev_data = data.values('state_choices')[0]['state_choices'] + data.values('prefix_verb_choices')[0]['prefix_verb_choices']
if( instance['state_or_verb'] not in ev_data):
raise APIException("PREFIX : Instance of State or Verb does not exist")
ei_data = data.values('function_choices')[0]['function_choices'] + data.values('item_choices')[0]['item_choices']+ data.values('flow_choices')[0]['flow_choices']+ data.values('state_value_choices')[0]['state_value_choices']
if( instance['item_function_flow_statevalue'] not in ei_data):
raise APIException("PREFIX : Instance of Object does not exist")
#find the class of the prefix
prefix_choices = inference.getclassofprefix(instance) prefix_choices = inference.getclassofprefix(instance)
if prefix_choices[0] == 'ERROR': if prefix_choices[0] == 'ERROR':
raise APIException("Prefix choices not in [P1-P3]") raise APIException("Prefix choices not in [P1-P3]")
else: else:
...@@ -222,8 +232,11 @@ class InferDetailsAPIView(RetrieveUpdateDestroyAPIView): ...@@ -222,8 +232,11 @@ 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, onto_file = inference.inferencing(project_title, boildata, prefixdata, maindata, suffixdata) try:
instance.update(inference_data = metrics) metrics, onto_file = inference.inferencing(instance['ontology_file'], project_title, boildata, prefixdata, maindata, suffixdata)
except:
raise APIException("Not all instances in the Ontology")
instance.update(inference_data = metrics, ontology_file=onto_file)
serializer.save() serializer.save()
def getboildata(self, pr): def getboildata(self, pr):
......
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