Commit 4de390ff authored by Thodoris Nestoridis's avatar Thodoris Nestoridis

inference 1st step (add table and ui button)

parent 1200b4d1
......@@ -30,6 +30,16 @@
</div>
</ul>
</div>
<div fxFlex fxLayout fxHide.xs fxLayoutAlign="end">
<ul *ngFor="let inf of infer;" fxLayout fxLayoutGap="15px" class="navigation-items">
<div>
<input class="btn btn-info"
type="button"
value="Inferencing"
(click)="updateInfer(inf.id)"/>
</div>
</ul>
</div>
</div>
</div>
......
import { Component, OnInit } from '@angular/core';
import { Boilerplate } from 'src/app/models/boilerplate.model';
import { BoilerplateData } from 'src/app/models/boilerplate.model';
import { InferenceResults } from 'src/app/models/boilerplate.model';
import { BoilerplateService } from 'src/app/services/boilerplate.service';
import { PrefixService } from 'src/app/services/prefix.service';
import { ActivatedRoute, Router } from '@angular/router';
......@@ -19,12 +20,17 @@ export class BoilerplateListComponent implements OnInit {
boilerplatesdata?: BoilerplateData[];
currentBoilerplate?: Boilerplate;
currentBoilerplatedata?: BoilerplateData;
currentInfer?: InferenceResults = {
infer_group_of_boilerplate: "",
inference_data: "",
}
currentIndex = -1;
title = '';
displayedColumns: string[] = ['id', 'title', 'has_prefix', 'has_main', 'has_suffix', 'action'];
newdisplayedColumns: string[] = ['id','title_data' ,'prefix_data', 'main_data', 'suffix_data', 'action'];
dataSource :Boilerplate[] = [{}];
newdataSource:BoilerplateData[] = [{}];
infer:InferenceResults[] = [{}];
dataofboilerplates: any [] = [];
aprefix: any [] = [];
......@@ -37,6 +43,7 @@ export class BoilerplateListComponent implements OnInit {
ngOnInit(): void {
this.retrieveBoilerplates();
this.retrieve();
this.getInfer()
}
retrieveBoilerplates(): void {
......@@ -104,4 +111,29 @@ export class BoilerplateListComponent implements OnInit {
this.router.navigate(['/groupboilerplates/'+ this.route.snapshot.params.gb +'/boilerplates'+ id])
}
getInfer(): void{
this.boilerplateService.getAllInfer(this.route.snapshot.params.gb)
.subscribe(
data => {
this.currentInfer = data[0];
this.infer = data;
console.log(data[0]);
},
error => {
console.log(error);
});
}
updateInfer(id: any): void {
this.boilerplateService.inferUpdate(this.route.snapshot.params.gb, id, this.currentInfer)
.subscribe(
data => {
console.log(data);
},
error => {
console.log(error);
});
}
}
......@@ -18,4 +18,10 @@ export class BoilerplateData {
export class GroupBoilerplate {
id?:any;
title_bgroup?: string;
}
export class InferenceResults {
id?:any;
infer_group_of_boilerplate?: any;
inference_data?: string;
}
\ No newline at end of file
......@@ -4,8 +4,10 @@ import { HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';
import { Boilerplate } from '../models/boilerplate.model';
import { GroupBoilerplate } from '../models/boilerplate.model';
import { InferenceResults } from '../models/boilerplate.model';
const baseUrl = '/boilerplates/';
const inferUrl = '/infer/';
const baseUrlgb = 'http://155.207.131.19:8000/api-auth/groupboilerplates/';
@Injectable({
......@@ -27,6 +29,14 @@ export class BoilerplateService {
return this.http.delete(`${baseUrlgb}${id}`);
}
getAllInfer(gb: any): Observable<InferenceResults[]> {
return this.http.get<[InferenceResults]>(baseUrlgb + gb + inferUrl);
}
inferUpdate(gb: any,id: any, data: any): Observable<any> {
return this.http.put(`${baseUrlgb}${gb}${inferUrl}${id}/`, data);
}
getAll(gb: any): Observable<Boilerplate[]> {
//console.log(baseUrlgb + gb + baseUrl)
return this.http.get<Boilerplate[]>(baseUrlgb + gb + baseUrl);
......
......@@ -6,9 +6,11 @@ from pygments import highlight
from reqman.apps.reqtool.rest_api.services.parse_ontologies import *
find_subclass_domain_range()
#MAIN SYNTAX
#print(get_main_sytax())
#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"),
......
......@@ -67,7 +67,8 @@ def create_extra_prefix(instance, now_prefix):
def create_infer_result(instance):
pass
infer = InferenceResults(owner_infer= instance.boilerplate_owner, infer_group_of_boilerplate = instance)
infer.save()
class BoilerplateGroup(models.Model):
......@@ -76,6 +77,7 @@ class BoilerplateGroup(models.Model):
def save(self, **kwargs):
super(BoilerplateGroup, self).save(**kwargs)
create_infer_result(self)
class Boilerplate(models.Model):
......@@ -189,9 +191,10 @@ class BoilerplateData(models.Model):
ordering = ['boilerplate_data_id']
#class InferenceResults(models.Model):
# owner_infer = models.ForeignKey(User, related_name='owner_infer', on_delete=models.CASCADE)
# inference_data = models.CharField(default="")
class InferenceResults(models.Model):
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)
inference_data = models.CharField(default="", max_length=1000, blank=True)
# class Meta:
# ordering = ['owner_infer']
class Meta:
ordering = ['owner_infer']
from rest_framework import serializers
from reqman.apps.reqtool.models.requirements import Prefix, Boilerplate, BoilerplateData, BoilerplateGroup
from reqman.apps.reqtool.models.requirements import Prefix, Boilerplate, BoilerplateData, BoilerplateGroup, InferenceResults
class BoilerplateSerializer(serializers.ModelSerializer):
......@@ -24,6 +24,12 @@ class BoilerplateDataSerializer(serializers.ModelSerializer):
model = BoilerplateData
fields = '__all__'
class InferSerializer(serializers.ModelSerializer):
owner_infer = serializers.ReadOnlyField(source='owner.username')
#infer_group_of_boilerplate = serializers.PrimaryKeyRelatedField(read_only=True)
class Meta:
model = InferenceResults
fields = '__all__'
class BoilerplateGroupSerializer(serializers.ModelSerializer):
boilerplate_owner = serializers.ReadOnlyField(source='owner.username')
......
def inferencing(prefix):
print(prefix.values_list())
for course in prefix:
print("this", course['system_fun_item'])
print("inferencing...")
\ No newline at end of file
......@@ -10,6 +10,9 @@ urlpatterns = [
path('groupboilerplates/', requirements_views.BoilerplateGroupCreateAPIView.as_view(), name='api-groupboilerplates-create'),
path('groupboilerplates/<int:pk>/', requirements_views.BoilerplateGroupDetailsAPIView.as_view(), name='api-groupboilerplates-list'),
path('groupboilerplates/<int:groupboil>/infer/', requirements_views.InferListAPIView.as_view(), name='api-infer-list'),
path('groupboilerplates/<int:groupboil>/infer/<int:pk>/', requirements_views.InferDetailsAPIView.as_view(), name='api-infer-details'),
path('groupboilerplates/<int:groupboil>/boilerplates/', requirements_views.BoilerplateListCreateAPIView.as_view(), name='api-requirements-list'),
path('groupboilerplates/<int:groupboil>/boilerplates/<int:pk>/', requirements_views.BoilerplateDetailsAPIView.as_view(), name='api-requirements-details'),
path('groupboilerplates/<int:groupboil>/boilerplates/boilerplatedata/', requirements_views.BoilerplateDataListAPIView.as_view(), name='api-boilerlplate-list-data'),
......
......@@ -8,13 +8,14 @@ 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 VERB_CHOICES, 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.rest_api.serializers.requirements import BoilerplateSerializer, PrefixSerializer, BoilerplateDataSerializer, BoilerplateGroupSerializer
from reqman.apps.reqtool.models.requirements import BoilerplateData, InferenceResults
from reqman.apps.reqtool.rest_api.serializers.requirements import BoilerplateSerializer, PrefixSerializer, BoilerplateDataSerializer, BoilerplateGroupSerializer, InferSerializer
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
from reqman.apps.reqtool.models.requirements import BoilerplateData
from django.shortcuts import get_object_or_404
......@@ -192,6 +193,61 @@ class BoilerplateDataListAPIView(ListAPIView):
queryset_boil_data = BoilerplateData.objects.filter(owner_data = self.request.user, group_of_boilerplate_data = group_gb)
return queryset_boil_data
class InferListAPIView(ListAPIView):
"""
API view to retrieve list of posts or create new
"""
permission_classes = [permissions.IsAuthenticatedOrReadOnly]
serializer_class = InferSerializer
#
#queryset = Prefix.objects.all()
def get_queryset(self):
group_pk = self.kwargs['groupboil']
#print(group_pk)
queryset_infer = InferenceResults.objects.filter(infer_group_of_boilerplate = group_pk)
return queryset_infer
class InferDetailsAPIView(RetrieveUpdateDestroyAPIView):
"""
API view to retrieve, update or delete post
"""
permission_classes = [permissions.IsAuthenticatedOrReadOnly]
serializer_class = InferSerializer
#queryset = Prefix.objects.all()
def get_queryset(self):
group_pk = self.kwargs['groupboil']
queryset_infer = InferenceResults.objects.filter(infer_group_of_boilerplate = group_pk)
return queryset_infer
##############################HERE########################
#Custom actions when PUT
def perform_update(self, serializer):
instance = serializer.validated_data
#add data in thn Model BoilerplateData
#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)
#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
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