Exemple #1
0
    def getManualExplanation(self, types, relations):
        es = ontologyStructureModel.EntityStructure()
        entitiesToBeFiltered = []

        for entityType in types:
            if entityType['option'] == 'all':
                entities = self.ir.getIndividualsByType(entityType['uri'])
                for entityUri in entities:
                    es.addEntity(entityUri)

            elif entityType['option'] == 'only_related':
                entities = self.ir.getIndividualsByType(entityType['uri'])
                for entityUri in entities:
                    entitiesToBeFiltered.append(entityUri) 
                    es.addEntity(entityUri)
            elif entityType['option'] == 'specific':
                es.addEntity(entityType['entityUri'])

        for relation in relations:
            entityRelations = self.ir.getRelationsByType(relation['source'], relation['name'], relation['target'])
            for entityRelation in entityRelations:
                es.addRelation(explanationHelper.getNameFromUri(entityRelation['name']), entityRelation['source'], entityRelation['target'])

        entitiesWithRelations = list(set([rel.source for rel in es.relations] + [rel.target for rel in es.relations]))
        
        for e in entitiesToBeFiltered:
            if e not in entitiesWithRelations:
                es.removeEntity(e)

        return es
Exemple #2
0
 def getRationaleOfArchitecture(self, architecturalPatternUri):
     es = ontologyStructureModel.EntityStructure()
     es.addEntity(architecturalPatternUri)
     for dc in self.ir.getRelations(architecturalPatternUri, self.baseUri + 'resultOf', self.baseUri + 'DesignOption'):
         es.addEntity(dc[1])
         es.addRelation('resultOf', architecturalPatternUri, dc[1])
         for rationale in self.ir.getRelations(dc[1], self.baseUri + 'basedOn'):
             es.addEntity(rationale[1])
             es.addRelation('basedOn', dc[1], rationale[1])
         for req in self.ir.getRelations(dc[1], self.baseUri + 'satisfies', self.baseUri + 'Requirement'):
             es.addEntity(req[1])
             es.addRelation('satisfies', dc[1], req[1])
         for causes_dc in self.ir.getRelations(dc[1], self.baseUri + 'causedBy', self.baseUri + 'DesignOption'):
             es.addEntity(causes_dc[1])
             es.addRelation('causedBy', dc[1], causes_dc[1])
             for rationale in self.ir.getRelations(causes_dc[1], self.baseUri + 'basedOn'):
                 es.addEntity(rationale[1])
                 es.addRelation('basedOn', causes_dc[1], rationale[1])
             for rationale in self.ir.getRelations(causes_dc[1], self.baseUri + 'satisfies', self.baseUri + 'Requirement'):
                 es.addEntity(rationale[1])
                 es.addRelation('satisfies', causes_dc[1], rationale[1])
         for pattern in self.ir.getRelations(dc[1], self.baseUri + 'resultsIn', self.baseUri + 'ArchitecturalPattern'):
             es.addEntity(pattern[1])
             es.addRelation('resultOf', pattern[1], dc[1])
     return es
Exemple #3
0
    def getFullPhyPatternArchitecture(self, patternUri=''):
        def callbackDevelopmentStructure(es, s):
            self.addRecursiveEntitiesAndRelations(es, s, self.baseUri + 'comprisesOf', self.baseUri + 'DevelopmentStructure', callback=callbackDevelopmentStructure)
            self.addRecursiveEntitiesAndRelations(es, s, self.baseUri + 'implementedBy', self.baseUri + 'ImplementationClass')

        def callbackPhysicalStructure(es, s):
            self.addRecursiveEntitiesAndRelations(es, s, self.baseUri + 'deploys', self.baseUri + 'DevelopmentStructure', callback=callbackDevelopmentStructure)

        def callbackRole(es, s):
            self.addRecursiveEntitiesAndRelations(es, s, self.baseUri + 'roleImplementedBy', self.baseUri + 'PhysicalStructure', callback=callbackPhysicalStructure)

        patterns = self.ir.getIndividualsByType(self.baseUri + 'ArchitecturalPattern')
        es = ontologyStructureModel.EntityStructure()

        if patternUri:
            es.addEntity(patternUri)
            self.addRecursiveEntitiesAndRelations(es, patternUri, self.baseUri + 'comprisesOf', self.baseUri + 'Role', callback=callbackRole)
        else:
            for pattern in patterns:
                es.addEntity(pattern)
                self.addRecursiveEntitiesAndRelations(es, pattern, self.baseUri + 'comprisesOf', self.baseUri + 'Role', callback=callbackRole)

        entityUris = [e.type for e in es.entities]
        if not self.baseUri + 'Device' in entityUris:
            es.entities = []
            es.relations = []

        return es
Exemple #4
0
    def getFunctionalityOfSystem(self):
        def callbackRequirement(es, s):
            self.addRecursiveEntitiesAndRelations(es, s, self.baseUri + 'partOf', self.baseUri + 'UseCase')
            self.addRecursiveEntitiesAndRelations(es, s, self.baseUri + 'explainedBy', self.baseUri + 'UserStory')

        es = ontologyStructureModel.EntityStructure()
        features = self.ir.getIndividualsByType(self.baseUri + 'Feature')

        for feature in features:
            es.addEntity(feature)
            self.addRecursiveEntitiesAndRelations(es, feature, self.baseUri + 'comprisesOf', self.baseUri + 'Requirement', callback=callbackRequirement)
        return es
Exemple #5
0
    def getOverviewPatternArchitecture(self, patternUri=''):
        patterns = self.ir.getIndividualsByType(self.baseUri + 'ArchitecturalPattern')
        es = ontologyStructureModel.EntityStructure()
        
        if patternUri:
            es.addEntity(patternUri)
            self.addRecursiveEntitiesAndRelations(es, patternUri, self.baseUri + 'comprisesOf', self.baseUri + 'Role')
        else:
            for pattern in patterns:
                es.addEntity(pattern)
                self.addRecursiveEntitiesAndRelations(es, pattern, self.baseUri + 'comprisesOf', self.baseUri + 'Role')

        return es
Exemple #6
0
    def getFunctionalBehaviorOfFeatureHelper(self, featureUri):
        def callbackDiagram(es, s):
            self.addRecursiveEntitiesAndRelations(es, s, self.baseUri + 'modeledIn', self.baseUri + 'Diagram')

        def callbackFunctionalBehavior(es, s):
            self.addRecursiveEntitiesAndRelations(es, s, self.baseUri + 'partOf', self.baseUri + 'UseCase', callback=callbackDiagram)
            self.addRecursiveEntitiesAndRelations(es, s, self.baseUri + 'explainedBy', self.baseUri + 'UserStory')

        es = ontologyStructureModel.EntityStructure()
        es.addEntity(featureUri)
        self.addRecursiveEntitiesAndRelations(es, featureUri, self.baseUri + 'comprisesOf', self.baseUri + 'Requirement', callback=callbackFunctionalBehavior)

        return es
Exemple #7
0
    def getDev(self, architecturalPatternUri):
        def callBackArchitecturalPattern(es, s):
            self.addRecursiveEntitiesAndRelations(es, s, self.baseUri + 'implementedBy', self.baseUri + 'ImplementationClass')

        def callbackDevStructure(es, s):
            self.addRecursiveEntitiesAndRelations(es, s, self.baseUri + 'comprisesOf', self.baseUri + 'DevelopmentStructure', callback=callBackArchitecturalPattern)
        
        es = ontologyStructureModel.EntityStructure()
        es.addEntity(architecturalPatternUri)
        for role in self.ir.getRelations(architecturalPatternUri, self.baseUri + 'comprisesOf', self.baseUri + 'Role'):
            es.addEntity(role[1])
            es.addRelation('comprisesOf' , architecturalPatternUri, role[1])
            self.addRecursiveEntitiesAndRelations(es, role[1], self.baseUri + 'roleImplementedBy', callback=callbackDevStructure)
        return es
Exemple #8
0
    def getImplementationToArchitecturalPatternMap(self, implementationUriList):
        def callBackArchitecturalPattern(es, s):
            self.addRecursiveEntitiesAndRelations(es, s, self.baseUri + 'partOf', self.baseUri + 'ArchitecturalPattern')

        def callbackPlaysRole(es, s):
            self.addRecursiveEntitiesAndRelations(es, s, self.baseUri + 'playsRole', self.baseUri + 'Role', callback=callBackArchitecturalPattern)
        
        es = ontologyStructureModel.EntityStructure()
        for i in implementationUriList:
            es.addEntity(i)
            for devStruct in self.ir.getRelations(i, self.baseUri + 'implements', self.baseUri + 'DevelopmentStructure'):
                es.addEntity(devStruct[1])
                es.addRelation('implements' , i, devStruct[1])
                self.addRecursiveEntitiesAndRelations(es, devStruct[1], self.baseUri + 'partOf', callback=callbackPlaysRole)
                self.addRecursiveEntitiesAndRelations(es, devStruct[1], self.baseUri + 'playsRole', self.baseUri + 'Role', callback=callBackArchitecturalPattern)
        return es
Exemple #9
0
    def getFeatureRole(self, featureUri):
        es = ontologyStructureModel.EntityStructure()
        es.addEntity(featureUri)
        requirements = [r[1] for r in self.ir.getRelations(featureUri, self.baseUri + 'comprisesOf', self.baseUri+ 'Requirement')]
        es.addAllEntities(requirements)
        es.addOneToManyRelation('comprisesOf', featureUri, requirements)

        for r in requirements:
            usecases = [uc[1] for uc in self.ir.getRelations(r, self.baseUri + 'partOf', self.baseUri + 'UseCase')]
            userstories = [us[1] for us in self.ir.getRelations(r, self.baseUri + 'explainedBy', self.baseUri + 'UserStory')]
            
            es.addAllEntities(usecases)
            es.addAllEntities(userstories)
            es.addOneToManyRelation('partOf', r, usecases)
            es.addOneToManyRelation('explainedBy', r, userstories)
        return es
Exemple #10
0
    def getLogBehaviorOfFeatureHelper(self, featureUri, behaviorUri, structureUri):
        def callbackDiagram(es, s):
            self.addRecursiveEntitiesAndRelations(es, s, self.baseUri + 'modeledIn', self.baseUri + 'Diagram')

        def callbackBehavior(es, s):
            self.addRecursiveEntitiesAndRelations(es, s, 'owl:sameAs', behaviorUri, callbackDiagram)
            self.addRecursiveEntitiesAndRelations(es, s, self.baseUri + 'expressedBy', behaviorUri, callbackDiagram)
 
        def callbackStructure(es, s):
            self.addRecursiveEntitiesAndRelations(es, s, self.baseUri + 'satisfiedBy', structureUri, callback=callbackBehavior)

        es = ontologyStructureModel.EntityStructure()
        es.addEntity(featureUri)
        self.addRecursiveEntitiesAndRelations(es, featureUri, self.baseUri + 'comprisesOf', self.baseUri + 'Requirement', callback=callbackStructure)

        return es
Exemple #11
0
    def constructMetaModel(self):
        allObjectsAndRelations = self.ir.getAllObjectsAndRelations()
        es = ontologyStructureModel.EntityStructure()
        entityToUriMap = {}
        for item in allObjectsAndRelations:
            e1 = ontologyStructureModel.Entity(item[0])
            e2 = ontologyStructureModel.Entity(item[2])
            es.addEntity(e1)
            es.addEntity(e2)
            entityToUriMap[explanationHelper.getNameFromUri(item[0])] = e1
            entityToUriMap[explanationHelper.getNameFromUri(item[2])] = e2
            es.addRelation(item[1], item[0], item[2])
            
        duplicates = {}
        for item in es.entities:
            if not explanationHelper.getNameFromUri(item.uri) in list(duplicates.keys()):
                duplicates[explanationHelper.getNameFromUri(item.uri)] = 1
            else:
                print('We got a duplicate key!')
                break

        print(duplicates)

        types = set()
        for item in es.entities:
            types.add(item.type)
        
        types = list(types)
        print('Types:')
        print(types)

        def getEntityType(entityUri):
            return entityToUriMap[explanationHelper.getNameFromUri(entityUri)].type

        typeRelations = []
        for item in es.relations:
            typeRelations.append({'name': item.name, 'source': getEntityType(item.source), 'target': getEntityType(item.target)})
        
        typeRelations = [dict(s) for s in set(frozenset(d.items()) for d in typeRelations)]

        print('Type relations:')
        print(typeRelations)

        typesAndRelations = {'types': types, 'relations': typeRelations}

        with open('C:/Users/SAMSUNG/Documents/ThesisProject/MasterThesisCode/Master-Thesis---OD3/Presentation/FlaskServer/static/ontologyRelations.js', 'w') as f:
            f.write(json.dumps(typesAndRelations))
Exemple #12
0
    def getLogicalFeatureToImplementationMapInner(self, featureUri):
        def callbackImplementedBy(es, s): 
            self.addRecursiveEntitiesAndRelations(es, s, self.baseUri + 'implementedBy')
        def callbackcomprisesOf(es, s): 
            self.addRecursiveEntitiesAndRelations(es,s, self.baseUri + 'comprisesOf', callback=callbackImplementedBy)
            callbackImplementedBy(es, s)

        es = ontologyStructureModel.EntityStructure()
        es.addEntity(featureUri)
        for req in self.ir.getRelations(featureUri, self.baseUri + 'comprisesOf', self.baseUri + 'Requirement'):
            es.addEntity(req[1])
            es.addRelation('comprisesOf', featureUri, req[1])
            for logStruct in self.ir.getRelations(req[1], self.baseUri + 'satisfiedBy', self.baseUri + 'LogicalStructure'):
                es.addEntity(logStruct[1])
                es.addRelation('satisfiedBy', req[1], logStruct[1])
                self.addRecursiveEntitiesAndRelations(es, logStruct[1], self.baseUri + 'designedBy', callback=callbackcomprisesOf)
        return es
Exemple #13
0
    def getOverviewFeatureToImplementationMap(self, featureUri):
        detailed = self.getDetailedFeatureToImplementationMap(featureUri)

        es = ontologyStructureModel.EntityStructure()

        architectureFragmentUris = []
        requirementUris = []
        for entity in detailed.entities:
            if self.baseUri + 'ArchitectureFragment' in entity.supertypes:
                architectureFragmentUris.append(entity.uri)
            elif self.baseUri + 'Requirement' in entity.supertypes:
                requirementUris.append(entity.uri)
            else:
                es.addEntity(entity)
        
        architectureEntity = ontologyStructureModel.DummyEntity('architecture_uri', 'ArchitectureFragments', supertypes=['ArchitectureFragment'])
        es.addEntity(architectureEntity)

        for relation in detailed.relations:
            if relation.source not in architectureFragmentUris and relation.target not in architectureFragmentUris:
                es.addRelation(relation)
            elif relation.source not in architectureFragmentUris and relation.target in architectureFragmentUris:
                es.addRelation(relation.name, relation.source, architectureEntity.uri)
            elif relation.source in architectureFragmentUris and relation.target not in architectureFragmentUris:
                es.addRelation(relation.name, architectureEntity.uri, relation.target)

        requirementEntity = ontologyStructureModel.DummyEntity('requirement_uri', 'Requirements', supertypes=['Requirement'])
        es.addEntity(requirementEntity)

        for relation in detailed.relations:
            if relation.source not in requirementUris and relation.target not in requirementUris:
                es.addRelation(relation)
            elif relation.source not in requirementUris and relation.target in requirementUris:
                es.addRelation(relation.name, relation.source, requirementEntity.uri)
            elif relation.source in requirementUris and relation.target not in requirementUris:
                es.addRelation(relation.name, requirementEntity.uri, relation.target)
        
        for relation in detailed.relations:
            if relation.source in architectureFragmentUris and relation.target in requirementUris:
                es.addRelation(relation.name, architectureEntity.uri, requirementEntity.uri)
            if relation.source in requirementUris and relation.target in architectureFragmentUris:
                es.addRelation(relation.name, requirementEntity.uri, architectureEntity.uri)

        return es
Exemple #14
0
    def getFullDevPatternArchitecture(self, patternUri=''):
        def callbackArchitectureFragment(es, s):
            self.addRecursiveEntitiesAndRelations(es, s, self.baseUri + 'comprisesOf', self.baseUri + 'DevelopmentStructure',  callback=callbackArchitectureFragment)
            self.addRecursiveEntitiesAndRelations(es, s, self.baseUri + 'implementedBy', self.baseUri + 'ImplementationClass')

        def callbackRole(es, s):
            self.addRecursiveEntitiesAndRelations(es, s, self.baseUri + 'roleImplementedBy', self.baseUri + 'DevelopmentStructure', callback=callbackArchitectureFragment)

        patterns = self.ir.getIndividualsByType(self.baseUri + 'ArchitecturalPattern')
        es = ontologyStructureModel.EntityStructure()
        
        if patternUri:
            es.addEntity(patternUri)
            self.addRecursiveEntitiesAndRelations(es, patternUri, self.baseUri + 'comprisesOf', self.baseUri + 'Role', callback=callbackRole)
        else:
            for pattern in patterns:
                es.addEntity(pattern)
                self.addRecursiveEntitiesAndRelations(es, pattern, self.baseUri + 'comprisesOf', self.baseUri + 'Role', callback=callbackRole)

        return es