def createSection(self, entityList, id, title, summary='', priority=1):
        if entityList and not summary:
            section = sectionModel.Section(id,
                                           title,
                                           sectionSummary=self.sectionSummary(
                                               entityList[0].type),
                                           priority=priority)
        else:
            section = sectionModel.Section(id,
                                           title,
                                           sectionSummary=summary,
                                           priority=priority)

        for entity in entityList:
            diagrams = []
            for diagram in entity.diagrams:
                caption = self.informationRetriever.getRelations(
                    diagram, self.baseUri + 'Caption')
                if caption:
                    caption = caption[0][1]

                diagrams.append({'uri': diagram, 'caption': caption})

            entitySection = sectionModel.Section(
                explanationHelper.getNameFromUri(entity.uri),
                explanationHelper.getNameOfEntity(entity),
                entityType=explanationHelper.getNameFromUri(entity.type),
                sectionSummary='',
                sectionTextContent=[
                    (explanationHelper.getNameFromUri(content[0]), content[1])
                    for content in entity.dataTypeProperties
                ],
                sectionDiagrams=diagrams)
            section.addChild(entitySection.toDict())
        return section
    def generateOverviewFeatureImplementationSummary(self, mainEntityUri,
                                                     structure):
        mainEntity = [
            entity for entity in structure.entities
            if entity.uri == mainEntityUri
        ][0]
        impl = list(
            filter(
                lambda e: self.baseUri + 'ImplementationClass' in e.supertypes,
                structure.entities))

        template = explanationHelper.openText(
            'static/explanationTemplates/OverviewViewImplementation.txt')
        summary = template.format(
            feature_name=self.styledName(
                explanationHelper.getNameOfEntity(mainEntity), 'class-font',
                mainEntity.type),
            no_style_feature_name=explanationHelper.getNameOfEntity(
                mainEntity),
            path=self.classesToText(structure.entities))
        question = self.getQuestion(summary)

        expTemplate = sectionModel.Template(question, summary)

        #Feature section
        sectionFeatureOverview = ''
        expTemplate.addSection(
            self.createSection([mainEntity],
                               'feature_section',
                               'Feature',
                               summary=sectionFeatureOverview,
                               priority=5).toDict())

        #Implmentation section
        sectionImplOverview = ''
        sectionImplOverview = sectionImplOverview.format(
            main_entity=explanationHelper.getNameOfEntity(mainEntity))
        expTemplate.addSection(
            self.createSection(impl,
                               'impl_section',
                               'Implementation classes',
                               summary=sectionImplOverview,
                               priority=3).toDict())

        return expTemplate
 def generateSpecificSystemPatternsDetailedSummary(self, structure,
                                                   mainEntity):
     noStylePatternName = explanationHelper.getNameOfEntity(mainEntity)
     patternName = self.styledName(noStylePatternName, 'class-font',
                                   self.baseUri + 'ArchitecturalPattern')
     roleName = self.styledName('roles', 'class-font',
                                self.baseUri + 'Role')
     template = explanationHelper.openText(
         'static/explanationTemplates/SpecificPatternInSystemDetailed.txt')
     summary = template.format(pattern=patternName,
                               no_style_pattern=noStylePatternName,
                               role=roleName,
                               structural_entities='structural entities',
                               path=self.classesToText(structure.entities))
     return self.generateGeneralSummary(structure, summary)
    def generatePopupFigureDescription(self, figureUri):
        figureEntity = ontologyStructureModel.Entity(figureUri)

        template = explanationHelper.openText(
            'static/explanationTemplates/FigureSummary.txt')

        relatedEntityUris = [
            ontologyStructureModel.Entity(entity[1])
            for entity in self.informationRetriever.getRelations(
                figureUri, self.baseUri + 'models')
        ]
        summary = template.format(
            classes=self.classesToText(relatedEntityUris))
        question = {'sub': 'View diagrams', 'orginial': ''}

        figureid = 'popup_' + explanationHelper.diagramUriToFileName(
            explanationHelper.getNameFromUri(figureUri))
        figuretitle = explanationHelper.getNameOfEntity(figureEntity)
        figureSummary = ''

        entityid = 'popup_entity_overview_' + explanationHelper.diagramUriToFileName(
            explanationHelper.getNameFromUri(figureUri))
        entitySummary = ''

        relatedEntities = relatedEntityUris
        figureSection = sectionModel.Section(
            figureid,
            figuretitle,
            figureSummary,
            priority=5,
            sectionTextContent=[
                (explanationHelper.getNameFromUri(content[0]), content[1])
                for content in figureEntity.dataTypeProperties
            ])
        entitySection = self.createSection(relatedEntities, entityid,
                                           'Entities related to diagram',
                                           entitySummary)

        template = sectionModel.Template(question, summary)
        template.addSection(figureSection.toDict())
        template.addSection(entitySection.toDict())

        return template
    def generateSystemPatternsOverviewSummary(self,
                                              structure,
                                              mainEntity=None):
        template = explanationHelper.openText(
            'static/explanationTemplates/PatternsInSystemOverview.txt')
        if mainEntity:
            pattern = explanationHelper.getNameOfEntity(mainEntity)
            pluralNumber = 1
        else:
            pattern = 'architectural patterns'
            pluralNumber = 2

        summary = template.format(
            path=self.classesToText(structure.entities),
            architectural_patterns=self.styledName(
                pattern, 'class-font', self.baseUri + 'ArchitecturalPattern'),
            roles=self.styledName('roles', 'class-font',
                                  self.baseUri + 'Role'),
            plural=self.pluralEngine.plural('its', pluralNumber))
        return self.generateGeneralSummary(structure, summary)
    def generatePatternFeatureImplementationSummary(self, mainEntityUri,
                                                    structure):

        mainEntity = ontologyStructureModel.Entity(mainEntityUri)
        impl = list(
            filter(lambda e: e.type == self.baseUri + 'ImplementationClass',
                   structure.entities))
        role = list(
            filter(lambda e: e.type == self.baseUri + 'Role',
                   structure.entities))
        arch = list(
            filter(lambda e: e.type == self.baseUri + 'ArchitecturalPattern',
                   structure.entities))
        developmentClasses = list(
            filter(lambda e: self.baseUri + 'DevelopmentClass' in e.supertypes,
                   structure.entities))
        developmentClassPackages = list(
            filter(
                lambda e: self.baseUri + 'DevelopmentClassPackage' in e.
                supertypes, structure.entities))
        developmentPackages = list(
            filter(
                lambda e: self.baseUri + 'DevelopmentPackage' in e.supertypes,
                structure.entities))

        template = explanationHelper.openText(
            'static/explanationTemplates/PatternViewImplementation.txt')
        summary = template.format(
            impl_class=self.styledName('Implementation classes', 'class-font',
                                       self.baseUri + 'ImplementationClass'),
            arch_patt=self.styledName('Architectural patterns', 'class-font',
                                      self.baseUri + 'ArchitecturalPattern'),
            path_inbetween=self.classesToText(structure.entities))
        question = self.getQuestion(summary)

        sectionImplOverview = ''
        sectionImplOverview = sectionImplOverview.format(
            main_entity=explanationHelper.getNameOfEntity(mainEntity))

        expTemplate = sectionModel.Template(question, summary)

        implSection = self.createSection(impl,
                                         'impl_section',
                                         'Implementation classes',
                                         summary=sectionImplOverview,
                                         priority=4)

        if developmentClasses:
            expTemplate.addSection(
                self.createSection(developmentClasses,
                                   'developmentClass_section',
                                   'Development classes',
                                   summary=self.sectionSummary(
                                       developmentClasses[0].type),
                                   priority=2).toDict())
        if developmentClassPackages:
            expTemplate.addSection(
                self.createSection(developmentClassPackages,
                                   'developmentClassPackage_section',
                                   'Development class packages',
                                   summary=self.sectionSummary(
                                       developmentClassPackages[0].type),
                                   priority=2).toDict())
        if developmentPackages:
            expTemplate.addSection(
                self.createSection(developmentPackages,
                                   'developmentPackage_section',
                                   'Development packages',
                                   summary=self.sectionSummary(
                                       developmentPackages[0].type),
                                   priority=2).toDict())

        sectionRoleOverview = ''
        roleSection = self.createSection(role,
                                         'role_section',
                                         'Roles',
                                         summary=sectionRoleOverview,
                                         priority=2)

        sectionArchOverview = ''
        archSection = self.createSection(arch,
                                         'arch_section',
                                         'Architectural patterns',
                                         summary=sectionArchOverview,
                                         priority=1)

        expTemplate.addSection(implSection.toDict())
        expTemplate.addSection(roleSection.toDict())
        expTemplate.addSection(archSection.toDict())

        return expTemplate
    def generateDetailedFeatureImplementationSummary(self, mainEntityUri,
                                                     structure):
        # Setup the summary
        main_entity = [
            entity for entity in structure.entities
            if entity.uri == mainEntityUri
        ][0]
        requirements = list(
            filter(lambda e: e.type == self.baseUri + 'FunctionalRequirement',
                   structure.entities))
        logicalClasses = list(
            filter(lambda e: self.baseUri + 'LogicalClass' in e.supertypes,
                   structure.entities))
        developmentClasses = list(
            filter(lambda e: self.baseUri + 'DevelopmentClass' in e.supertypes,
                   structure.entities))
        developmentClassPackages = list(
            filter(
                lambda e: self.baseUri + 'DevelopmentClassPackage' in e.
                supertypes, structure.entities))
        developmentPackages = list(
            filter(lambda e: self.baseUri + 'Package' in e.supertypes,
                   structure.entities))
        implementation = list(
            filter(
                lambda e: self.baseUri + 'ImplementationClass' in e.supertypes,
                structure.entities))

        template = explanationHelper.openText(
            'static/explanationTemplates/DetailedViewImplementation.txt')
        entityName = explanationHelper.getNameOfEntity(main_entity)
        summary = template.format(
            no_style_feature_name=entityName,
            feature_name=self.styledName(
                explanationHelper.getNameOfEntity(main_entity),
                'entity-font',
                entityType=main_entity.type),
            target_type_name=self.styledName('implementation',
                                             'class-font',
                                             entityType=self.baseUri +
                                             'ImplementationClass'),
            path_inbetween=self.classesToText(structure.entities))

        question = self.getQuestion(summary)
        expTemplate = sectionModel.Template(question, summary)

        #Logical section
        logicalSection = self.createSection(logicalClasses,
                                            'logical_section',
                                            'Logical classes',
                                            summary=self.sectionSummary(
                                                logicalClasses[0].type),
                                            priority=3)

        overviewDiagrams = self.getOverviewDiagrams(structure,
                                                    'LogicalStructure')

        overviewIdCounter = 0
        for key, value in overviewDiagrams.items():
            dummySection = sectionModel.Section(
                'overview' + str(overviewIdCounter),
                value['name'],
                sectionSummary=value['description'],
                sectionDiagrams=[{
                    'uri': key,
                    'caption': value['caption']
                }])
            overviewIdCounter += 1
        overviewSectionSummary = 'This section presents and describes diagrams that encapsulate all of the logical classes found in this explanation.'
        overviewSection = sectionModel.Section(
            'logical_overview',
            'Overview',
            sectionSummary=overviewSectionSummary,
            priority=99)
        overviewSection.addChild(dummySection.toDict())
        logicalSection.addChild(overviewSection.toDict())

        expTemplate.addSection(logicalSection.toDict())

        #Implementation section
        expTemplate.addSection(
            self.createSection(implementation,
                               'implementation_section',
                               'Implementation classes',
                               summary=self.sectionSummary(
                                   implementation[0].type),
                               priority=1).toDict())

        #Development structure section
        if developmentClasses:
            expTemplate.addSection(
                self.createSection(developmentClasses,
                                   'developmentClass_section',
                                   'Development classes',
                                   summary=self.sectionSummary(
                                       developmentClasses[0].type),
                                   priority=2).toDict())

        #Development structure section
        if developmentClassPackages:
            expTemplate.addSection(
                self.createSection(developmentClassPackages,
                                   'developmentClassPackage_section',
                                   'Development class packages',
                                   summary=self.sectionSummary(
                                       developmentClassPackages[0].type),
                                   priority=2).toDict())

        #Development structure section
        if developmentPackages:
            expTemplate.addSection(
                self.createSection(developmentPackages,
                                   'developmentPackage_section',
                                   'Development packages',
                                   summary=self.sectionSummary(
                                       developmentPackages[0].type),
                                   priority=2).toDict())

        #Requirements section
        expTemplate.addSection(
            self.createSection(requirements,
                               'requirements_section',
                               'Functional requirements',
                               summary=self.sectionSummary(
                                   requirements[0].type),
                               priority=4).toDict())

        #Feature section
        expTemplate.addSection(
            self.createSection([main_entity],
                               'feature_section',
                               'Feature',
                               summary=self.sectionSummary(main_entity.type),
                               priority=5).toDict())

        return expTemplate.toDict()
    def generateRationaleSummary(self, pattern, structure):
        pattern_entity = [
            entity for entity in structure.entities if entity.uri == pattern
        ][0]

        patterns = list(
            filter(
                lambda e: self.baseUri + 'ArchitecturalPattern' in e.
                supertypes, structure.entities))
        designOptions = list(
            filter(lambda e: self.baseUri + 'DesignOption' in e.supertypes,
                   structure.entities))
        arguments = list(
            filter(lambda e: e.type == self.baseUri + 'Argument',
                   structure.entities))
        assumptions = list(
            filter(lambda e: e.type == self.baseUri + 'Assumption',
                   structure.entities))
        constraints = list(
            filter(lambda e: e.type == self.baseUri + 'Constraint',
                   structure.entities))
        nonFuncReqs = list(
            filter(
                lambda e: e.type == self.baseUri + 'NonFunctionalRequirement',
                structure.entities))

        template = explanationHelper.openText(
            'static/explanationTemplates/RationaleOfArchitecture.txt')

        summary = template.format(
            no_style_arch_patt=explanationHelper.getNameOfEntity(
                pattern_entity),
            arch_patt=self.styledName(
                explanationHelper.getNameOfEntity(pattern_entity),
                'class-font', pattern_entity.type),
            path=self.classesToText(structure.entities))
        question = self.getQuestion(summary)

        expTemplate = sectionModel.Template(question, summary)

        #Pattern section
        sectionDOOverview = ''
        expTemplate.addSection(
            self.createSection(patterns,
                               'pattern_section',
                               'Architectural patterns',
                               summary=sectionDOOverview,
                               priority=5).toDict())

        #Choice section
        sectionDOOverview = ''
        expTemplate.addSection(
            self.createSection(designOptions,
                               'design_option_section',
                               'Design options',
                               summary=sectionDOOverview,
                               priority=4).toDict())

        #Arguments section
        sectionArgOverview = ''
        expTemplate.addSection(
            self.createSection(arguments,
                               'arguments_section',
                               'Arguments',
                               summary=sectionArgOverview,
                               priority=3).toDict())

        #Constraint section
        sectionConOverview = ''
        expTemplate.addSection(
            self.createSection(constraints,
                               'constraint_section',
                               'Constraints',
                               summary=sectionConOverview,
                               priority=2).toDict())
        #Assumption section
        sectionAssOverview = ''
        expTemplate.addSection(
            self.createSection(assumptions,
                               'assumption_section',
                               'Assumptions',
                               summary=sectionAssOverview,
                               priority=1).toDict())
        #Non functional section
        sectionNonFuncOverview = ''
        expTemplate.addSection(
            self.createSection(nonFuncReqs,
                               'non_functional_section',
                               'Non-functional requirements',
                               summary=sectionNonFuncOverview,
                               priority=0).toDict())

        return expTemplate.toDict()
    def generateFunctionalBehaviorSummary(self, featureUri, structure):
        feature_entity = [
            entity for entity in structure.entities if entity.uri == featureUri
        ][0]
        requirements = list(
            filter(lambda e: e.type == self.baseUri + 'FunctionalRequirement',
                   structure.entities))
        userstories = list(
            filter(lambda e: self.baseUri + 'UserStory' == e.type,
                   structure.entities))
        usecases = list(
            filter(lambda e: self.baseUri + 'UseCase' == e.type,
                   structure.entities))
        diagrams = list(
            filter(lambda e: e.type == self.baseUri + 'Diagram',
                   structure.entities))

        template = explanationHelper.openText(
            'static/explanationTemplates/BehaviorOfFeature.txt')

        summary = template.format(
            feature_name=self.styledName(
                explanationHelper.getNameOfEntity(feature_entity),
                'entity-font',
                entityType=feature_entity.type),
            no_style_feature_name=explanationHelper.getNameOfEntity(
                feature_entity),
            point_of_view='Functional point of view',
            path=self.classesToText(structure.entities))

        question = self.getQuestion(summary)
        expTemplate = sectionModel.Template(question, summary)

        #Feature section
        expTemplate.addSection(
            self.createSection([feature_entity],
                               'feature_section',
                               'Features',
                               summary='',
                               priority=5).toDict())
        #Requirements section
        expTemplate.addSection(
            self.createSection(requirements,
                               'requirements_section',
                               'Requirements',
                               summary='',
                               priority=4).toDict())
        #UserStory section
        expTemplate.addSection(
            self.createSection(usecases,
                               'use_case_section',
                               'Use cases',
                               summary='',
                               priority=3).toDict())

        #Usecase section
        expTemplate.addSection(
            self.createSection(userstories,
                               'user_story_section',
                               'User stories',
                               summary='',
                               priority=2).toDict())
        #Diagram section
        expTemplate.addSection(
            self.createSection(diagrams,
                               'diagram_section',
                               'Diagram entities',
                               summary='',
                               priority=1).toDict())

        return expTemplate.toDict()
    def generateBehaviorSummary(self, featureUri, structure, viewType):
        if viewType == 'functional':
            return self.generateFunctionalBehaviorSummary(
                featureUri, structure)
        if viewType == 'logical':
            structureTypeUri = 'LogicalStructure'
            behaviorTypeUri = 'LogicalBehavior'
            viewTypeUri = 'Logical'
        elif viewType == 'development':
            structureTypeUri = 'DevelopmentStructure'
            behaviorTypeUri = 'DevelopmentBehavior'
            viewTypeUri = 'Development'
        elif viewType == 'ui':
            structureTypeUri = 'UIStructure'
            behaviorTypeUri = 'UIBehavior'
            viewTypeUri = 'UI'
        else:
            return {}

        if (not structure.entities):
            question = self.getQuestion(
                explanationHelper.openText(
                    'static/explanationTemplates/BehaviorOfFeature.txt'))
            return sectionModel.Template(
                question,
                '<font style="color:red;font-weight:bold;font-size:20">No documented data of the '
                + viewType + ' behavior of this feature was found.</font>')

        feature_entity = [
            entity for entity in structure.entities if entity.uri == featureUri
        ][0]
        requirements = list(
            filter(lambda e: e.type == self.baseUri + 'FunctionalRequirement',
                   structure.entities))
        structures = list(
            filter(lambda e: self.baseUri + structureTypeUri in e.supertypes,
                   structure.entities))
        behavior = list(
            filter(lambda e: self.baseUri + behaviorTypeUri in e.supertypes,
                   structure.entities))
        diagrams = list(
            filter(lambda e: e.type == self.baseUri + 'Diagram',
                   structure.entities))

        template = explanationHelper.openText(
            'static/explanationTemplates/BehaviorOfFeature.txt')

        summary = template.format(
            feature_name=self.styledName(
                explanationHelper.getNameOfEntity(feature_entity),
                'entity-font',
                entityType=feature_entity.type),
            no_style_feature_name=explanationHelper.getNameOfEntity(
                feature_entity),
            point_of_view=self.styledName(viewType + ' point of view',
                                          'class-font',
                                          entityType=self.baseUri +
                                          viewTypeUri),
            path=self.classesToText(structure.entities))

        question = self.getQuestion(summary)
        expTemplate = sectionModel.Template(question, summary)

        #Feature section
        sectionReqOverview = ''
        expTemplate.addSection(
            self.createSection([feature_entity],
                               'features_section',
                               'Features',
                               summary=sectionReqOverview,
                               priority=4).toDict())
        #Requirements section
        sectionReqOverview = ''
        expTemplate.addSection(
            self.createSection(requirements,
                               'requirements_section',
                               'Requirement',
                               summary=sectionReqOverview,
                               priority=4).toDict())
        #Structures section
        sectionStructOverview = ''
        expTemplate.addSection(
            self.createSection(structures,
                               'structures_section',
                               'Structure entities',
                               summary=sectionStructOverview,
                               priority=3).toDict())
        #Behavior section
        sectionBehOverview = ''
        expTemplate.addSection(
            self.createSection(behavior,
                               'behavior_section',
                               'Behavior entities',
                               summary=sectionBehOverview,
                               priority=2).toDict())
        #Diagrams section
        sectionDiaOverview = ''
        expTemplate.addSection(
            self.createSection(diagrams,
                               'diagram_section',
                               'Diagrams',
                               summary=sectionDiaOverview,
                               priority=1).toDict())

        return expTemplate.toDict()
    def generateFeatureRoleSummary(self, featureUri, structure):
        feature_entity = [
            entity for entity in structure.entities if entity.uri == featureUri
        ][0]
        requirements = list(
            filter(lambda e: e.type == self.baseUri + 'FunctionalRequirement',
                   structure.entities))
        use_cases = list(
            filter(lambda e: e.type == self.baseUri + 'UseCase',
                   structure.entities))
        user_stories = list(
            filter(lambda e: e.type == self.baseUri + 'UserStory',
                   structure.entities))

        template = explanationHelper.openText(
            'static/explanationTemplates/FeatureRole.txt')

        summary = template.format(
            no_style_feature_name=explanationHelper.getNameOfEntity(
                feature_entity),
            feature_name=self.styledName(
                explanationHelper.getNameOfEntity(feature_entity),
                'class-font', feature_entity.type),
            path=self.classesToText(structure.entities))

        question = self.getQuestion(summary)

        expTemplate = sectionModel.Template(question, summary)

        #Features section
        expTemplate.addSection(
            self.createSection([feature_entity],
                               'features_section',
                               'Feature',
                               summary='',
                               priority=3).toDict())

        #Requirements section
        expTemplate.addSection(
            self.createSection(requirements,
                               'requirements_section',
                               'FunctionalRequirement',
                               summary='',
                               priority=3).toDict())

        #Use cases section
        expTemplate.addSection(
            self.createSection(use_cases,
                               'use_case_section',
                               'UseCase',
                               summary='',
                               priority=2).toDict())

        #User story section
        expTemplate.addSection(
            self.createSection(user_stories,
                               'user_story_section',
                               'UserStory',
                               summary='',
                               priority=1).toDict())

        return expTemplate.toDict()