def test__11_model_creation_with_devices(self):
        """
        Test the creation of a models file with DeviceClasses.
        The models are used for further tests
        """
        vocabulary = VocabularyConfigurator.create_vocabulary(
            VocabularySettings(pascal_case_class_labels=False,
                               pascal_case_individual_labels=False,
                               camel_case_property_labels=False,
                               camel_case_datatype_labels=False,
                               pascal_case_datatype_enum_labels=False))

        vocabulary = \
            VocabularyConfigurator.add_ontology_to_vocabulary_as_file(
                vocabulary=vocabulary,
                path_to_file=self.get_file_path(
                    'ontology_files/ParsingTesterOntology.ttl'))

        vocabulary.get_data_property(
            "http://www.semanticweb.org/redin/ontologies/2020/11/untitled"
            "-ontology-25#commandProp").field_type = DataFieldType.command
        vocabulary.get_data_property(
            "http://www.semanticweb.org/redin/ontologies/2020/11/untitled"
            "-ontology-25#attributeProp").field_type = \
            DataFieldType.device_attribute

        VocabularyConfigurator.generate_vocabulary_models(
            vocabulary, f"{self.get_file_path('')}/", "models2")
    def test_1_model_creation(self):
        """
        Build the model used by all other tests
        """
        vocabulary = VocabularyConfigurator.create_vocabulary(
            VocabularySettings(pascal_case_class_labels=False,
                               pascal_case_individual_labels=False,
                               camel_case_property_labels=False,
                               camel_case_datatype_labels=False,
                               pascal_case_datatype_enum_labels=False))

        vocabulary = \
            VocabularyConfigurator.add_ontology_to_vocabulary_as_file(
                vocabulary=vocabulary,
                path_to_file=self.get_file_path(
                    'ontology_files/ParsingTesterOntology.ttl'))

        # Test part can only be executed locally, as the gitlab runner can´t
        # access the WWW
        vocabulary = \
            VocabularyConfigurator.add_ontology_to_vocabulary_as_link(
                vocabulary=vocabulary,
                link="https://ontology.tno.nl/saref.ttl")

        self.assertEqual(vocabulary.get_source_list()[1].source_name,
                         "saref.ttl")
        self.assertTrue(
            "https://w3id.org/saref#LightingDevice" in vocabulary.classes)

        VocabularyConfigurator.generate_vocabulary_models(
            vocabulary, f"{self.get_file_path('')}/", "models")
Beispiel #3
0
 def test_valid_test(self):
     self.assertEqual(
         VocabularyConfigurator.is_vocabulary_valid(self.vocabulary_2),
         False)
     self.assertEqual(
         VocabularyConfigurator.is_vocabulary_valid(self.vocabulary_1),
         True)
     self.assertEqual(
         VocabularyConfigurator.is_vocabulary_valid(self.vocabulary_3),
         True)
Beispiel #4
0
    def setUp(self) -> None:
        # Build vocabularies
        vocabulary = VocabularyConfigurator.create_vocabulary(
            VocabularySettings(pascal_case_class_labels=False,
                               pascal_case_individual_labels=False,
                               camel_case_property_labels=False,
                               camel_case_datatype_labels=False,
                               pascal_case_datatype_enum_labels=False))

        vocabulary_1 = \
            VocabularyConfigurator.add_ontology_to_vocabulary_as_file(
                vocabulary=vocabulary,
                path_to_file=self.get_file_path(
                    'ontology_files/RoomFloorOntology.ttl'))

        with open(self.get_file_path(
                'ontology_files/RoomFloor_Duplicate_Labels.ttl'), 'r') \
                as file:
            data = file.read()

        vocabulary_2 = \
            VocabularyConfigurator.add_ontology_to_vocabulary_as_string(
                vocabulary=vocabulary_1,
                source_name='RoomFloorOntology_Duplicate_Labels',
                source_content=data
            )

        vocabulary_3 = \
            VocabularyConfigurator.add_ontology_to_vocabulary_as_file(
                vocabulary=vocabulary,
                path_to_file=self.get_file_path(
                    'ontology_files/RoomFloorOntology.ttl'),
                source_name='test_name'
            )
        vocabulary_3 = \
            VocabularyConfigurator.add_ontology_to_vocabulary_as_file(
                vocabulary=vocabulary_3,
                path_to_file=self.get_file_path(
                    'ontology_files/ParsingTesterOntology.ttl')
            )

        self.vocabulary = vocabulary
        self.vocabulary_1 = vocabulary_1
        self.vocabulary_2 = vocabulary_2
        self.vocabulary_3 = vocabulary_3
Beispiel #5
0
    def _save_initial_label_summary(cls, vocabulary: Vocabulary):
        """
        Save the label_summary existing after parsing, before the user
        changed labels

        Args:
            vocabulary: vocabulary of which the label summary should be saved

        Returns:
            None
        """
        from filip.semantics.vocabulary_configurator import \
            VocabularyConfigurator
        vocabulary.original_label_summary = \
            VocabularyConfigurator.get_label_conflicts_in_vocabulary(
                vocabulary=vocabulary)
Beispiel #6
0
    def test_vocabulary_composition(self):
        """
        Test for fiware header
        """
        # makes lines a bit shorter and more readable
        vocabulary = self.vocabulary
        vocabulary_1 = self.vocabulary_1
        vocabulary_2 = self.vocabulary_2
        vocabulary_3 = self.vocabulary_3

        # test number of sources; each vocabulary has one PREDEFINED source
        self.assertEqual(len(vocabulary_1.sources), 2)
        self.assertEqual(len(vocabulary_2.sources), 3)
        self.assertEqual(len(vocabulary_3.sources), 3)

        # test source names
        self.assertIn('RoomFloorOntology',
                      [n.source_name for n in vocabulary_1.sources.values()])

        self.assertIn('RoomFloorOntology',
                      [n.source_name for n in vocabulary_2.sources.values()])
        self.assertIn('RoomFloorOntology_Duplicate_Labels',
                      [n.source_name for n in vocabulary_2.sources.values()])

        self.assertIn('test_name',
                      [n.source_name for n in vocabulary_3.sources.values()])

        # test content of vocabulary
        self.assertEqual(len(vocabulary_2.classes), 10)
        self.assertEqual(len(vocabulary_3.classes), 18)

        # test deletion of source
        source_id = [
            s.id for s in vocabulary_3.sources.values()
            if s.source_name == "test_name"
        ][0]
        vocabulary_4 = VocabularyConfigurator.delete_source_from_vocabulary(
            vocabulary=vocabulary_3, source_id=source_id)
        self.assertIn('test_name',
                      [n.source_name for n in vocabulary_3.sources.values()])
        self.assertNotIn(
            'test_name',
            [n.source_name for n in vocabulary_4.sources.values()])
Beispiel #7
0
    def test_build_models(self):

        if not VocabularyConfigurator.is_vocabulary_valid(self.vocabulary_1):
            raise Exception
    # CombinedRelation (CombinedObject- or CombinedDataRelation depending on
    # the property type)
    #
    # A vocabulary can also contain Individuals. An individual is an
    # immutable instance of a class without values. It can be regarded as a
    # type of enum value.

    # ## 1.1 To automatically adapt the label of the entities in the ontology we
    # can pass some settings to our vocabulary:
    settings = VocabularySettings(pascal_case_class_labels=True,
                                  pascal_case_individual_labels=True,
                                  camel_case_property_labels=True,
                                  camel_case_datatype_labels=True,
                                  pascal_case_datatype_enum_labels=True)
    # We create our new blank vocabulary:
    vocabulary = VocabularyConfigurator.create_vocabulary(settings=settings)

    # # 2 Adding ontologies
    #
    # We now add the wanted ontologies to our vocabulary.
    # The ontologies can be inserted via a file, a weblink or as content string.
    # The ontologies need to be Turtle encoded
    # We always get a new vocabulary object returned

    # ### 2.0.1 as file
    vocabulary = \
        VocabularyConfigurator.add_ontology_to_vocabulary_as_file(
            vocabulary=vocabulary,
            path_to_file='ontology_files/building circuits.owl')

    # ### 2.0.2 as string