fuzzy-dl-owl2 1.0.4__py3-none-any.whl → 1.0.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fuzzy_dl_owl2/fuzzydl/fuzzydl_to_owl2.py +224 -61
- fuzzy_dl_owl2/fuzzydl/util/__init__.py +1 -0
- fuzzy_dl_owl2/fuzzyowl2/fuzzyowl2.py +22 -16
- fuzzy_dl_owl2/fuzzyowl2/fuzzyowl2_to_fuzzydl.py +3 -4
- fuzzy_dl_owl2/fuzzyowl2/owl_types/modified_property.py +7 -1
- fuzzy_dl_owl2/fuzzyowl2/parser/__init__.py +2 -1
- fuzzy_dl_owl2/fuzzyowl2/parser/owl2_parser.py +22 -15
- fuzzy_dl_owl2/fuzzyowl2/parser/owl2_xml_parser.py +226 -0
- fuzzy_dl_owl2/fuzzyowl2/util/__init__.py +1 -0
- fuzzy_dl_owl2/fuzzyowl2/util/constants.py +138 -52
- fuzzy_dl_owl2/fuzzyowl2/util/fuzzy_xml.py +107 -0
- {fuzzy_dl_owl2-1.0.4.dist-info → fuzzy_dl_owl2-1.0.6.dist-info}/METADATA +2 -2
- {fuzzy_dl_owl2-1.0.4.dist-info → fuzzy_dl_owl2-1.0.6.dist-info}/RECORD +15 -13
- {fuzzy_dl_owl2-1.0.4.dist-info → fuzzy_dl_owl2-1.0.6.dist-info}/LICENSE +0 -0
- {fuzzy_dl_owl2-1.0.4.dist-info → fuzzy_dl_owl2-1.0.6.dist-info}/WHEEL +0 -0
|
@@ -5,6 +5,8 @@ import sys
|
|
|
5
5
|
import typing
|
|
6
6
|
from functools import partial
|
|
7
7
|
|
|
8
|
+
from rdflib import RDF, XSD, Literal, Namespace, URIRef
|
|
9
|
+
|
|
8
10
|
from fuzzy_dl_owl2.fuzzydl.assertion.assertion import Assertion
|
|
9
11
|
from fuzzy_dl_owl2.fuzzydl.concept.all_some_concept import AllSomeConcept
|
|
10
12
|
from fuzzy_dl_owl2.fuzzydl.concept.choquet_integral import ChoquetIntegral
|
|
@@ -62,6 +64,7 @@ from fuzzy_dl_owl2.fuzzydl.util import constants
|
|
|
62
64
|
from fuzzy_dl_owl2.fuzzydl.util.constants import ConceptType, ConcreteFeatureType
|
|
63
65
|
from fuzzy_dl_owl2.fuzzydl.util.util import Util
|
|
64
66
|
from fuzzy_dl_owl2.fuzzyowl2.util.constants import FuzzyOWL2Keyword
|
|
67
|
+
from fuzzy_dl_owl2.fuzzyowl2.util.fuzzy_xml import FuzzyXML
|
|
65
68
|
from pyowl2.abstracts.axiom import OWLAxiom
|
|
66
69
|
from pyowl2.abstracts.class_expression import OWLClassExpression
|
|
67
70
|
from pyowl2.abstracts.data_range import OWLDataRange
|
|
@@ -125,7 +128,6 @@ from pyowl2.expressions.object_property import OWLObjectProperty
|
|
|
125
128
|
from pyowl2.individual.named_individual import OWLNamedIndividual
|
|
126
129
|
from pyowl2.literal.literal import OWLLiteral
|
|
127
130
|
from pyowl2.ontology import OWLOntology
|
|
128
|
-
from rdflib import RDF, XSD, Literal, Namespace, URIRef
|
|
129
131
|
|
|
130
132
|
|
|
131
133
|
# @utils.timer_decorator
|
|
@@ -275,11 +277,24 @@ class FuzzydlToOwl2:
|
|
|
275
277
|
c4: OWLClassExpression = self.get_new_atomic_class(str(c))
|
|
276
278
|
c3: OWLClassExpression = self.get_base(c.c1)
|
|
277
279
|
self.concepts[str(c)] = c3
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
280
|
+
|
|
281
|
+
main_xml = FuzzyXML.build_main_xml(FuzzyOWL2Keyword.CONCEPT.get_str_value())
|
|
282
|
+
concept_xml = FuzzyXML.build_concept_xml(
|
|
283
|
+
FuzzyOWL2Keyword.MODIFIED.get_str_value(),
|
|
284
|
+
{
|
|
285
|
+
FuzzyOWL2Keyword.MODIFIER.get_str_value(): str(
|
|
286
|
+
self.modifiers[str(c)]
|
|
287
|
+
),
|
|
288
|
+
FuzzyOWL2Keyword.BASE.get_str_value(): str(c3),
|
|
289
|
+
},
|
|
282
290
|
)
|
|
291
|
+
main_xml.append(concept_xml)
|
|
292
|
+
annotation: str = FuzzyXML.to_str(main_xml)
|
|
293
|
+
# annotation: str = (
|
|
294
|
+
# f'<{FuzzyOWL2Keyword.FUZZY_OWL_2.get_str_value()} {FuzzyOWL2Keyword.FUZZY_TYPE.get_str_value()}="{FuzzyOWL2Keyword.CONCEPT.get_str_value()}">\n',
|
|
295
|
+
# f'\t<{FuzzyOWL2Keyword.CONCEPT.get_tag_name()} {FuzzyOWL2Keyword.TYPE.get_str_value()}="{FuzzyOWL2Keyword.MODIFIED.get_str_value()}" {FuzzyOWL2Keyword.MODIFIER.get_str_value()}="{self.modifiers[str(c)]}" {FuzzyOWL2Keyword.BASE.get_str_value()}="{c3}"/>\n',
|
|
296
|
+
# f"</{FuzzyOWL2Keyword.FUZZY_OWL_2.get_str_value()}>",
|
|
297
|
+
# )
|
|
283
298
|
self.add_entity_annotation(annotation, c4)
|
|
284
299
|
return c4
|
|
285
300
|
elif c_type == ConceptType.SELF:
|
|
@@ -330,11 +345,22 @@ class FuzzydlToOwl2:
|
|
|
330
345
|
c: WeightedConcept = typing.cast(WeightedConcept, c)
|
|
331
346
|
c4: OWLClassExpression = self.get_new_atomic_class(str(c))
|
|
332
347
|
c3: OWLClassExpression = self.get_base(c.c1)
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
348
|
+
|
|
349
|
+
main_xml = FuzzyXML.build_main_xml(FuzzyOWL2Keyword.CONCEPT.get_str_value())
|
|
350
|
+
concept_xml = FuzzyXML.build_concept_xml(
|
|
351
|
+
FuzzyOWL2Keyword.WEIGHTED.get_str_value(),
|
|
352
|
+
{
|
|
353
|
+
FuzzyOWL2Keyword.DEGREE_VALUE.get_str_value(): str(c.weight),
|
|
354
|
+
FuzzyOWL2Keyword.BASE.get_str_value(): str(c3),
|
|
355
|
+
},
|
|
337
356
|
)
|
|
357
|
+
main_xml.append(concept_xml)
|
|
358
|
+
annotation: str = FuzzyXML.to_str(main_xml)
|
|
359
|
+
# annotation: str = (
|
|
360
|
+
# f'<{FuzzyOWL2Keyword.FUZZY_OWL_2.get_str_value()} {FuzzyOWL2Keyword.FUZZY_TYPE.get_str_value()}="{FuzzyOWL2Keyword.CONCEPT.get_str_value()}">\n',
|
|
361
|
+
# f'\t<{FuzzyOWL2Keyword.CONCEPT.get_tag_name()} {FuzzyOWL2Keyword.TYPE.get_str_value()}="{FuzzyOWL2Keyword.WEIGHTED.get_str_value()}" {FuzzyOWL2Keyword.DEGREE_VALUE.get_str_value()}="{c.weight}" {FuzzyOWL2Keyword.BASE.get_str_value()}="{c3}"/>\n',
|
|
362
|
+
# f"</{FuzzyOWL2Keyword.FUZZY_OWL_2.get_str_value()}>",
|
|
363
|
+
# )
|
|
338
364
|
self.add_entity_annotation(annotation, c3)
|
|
339
365
|
return c4
|
|
340
366
|
elif c_type in (
|
|
@@ -346,12 +372,14 @@ class FuzzydlToOwl2:
|
|
|
346
372
|
return self.__get_class_weighted_min_max_sum(c)
|
|
347
373
|
elif c_type in (
|
|
348
374
|
ConceptType.OWA,
|
|
349
|
-
ConceptType.QUANTIFIED_OWA,
|
|
375
|
+
# ConceptType.QUANTIFIED_OWA,
|
|
350
376
|
ConceptType.CHOQUET_INTEGRAL,
|
|
351
377
|
ConceptType.SUGENO_INTEGRAL,
|
|
352
378
|
ConceptType.QUASI_SUGENO_INTEGRAL,
|
|
353
379
|
):
|
|
354
380
|
return self.__get_class_weighted(c)
|
|
381
|
+
elif c_type == ConceptType.QUANTIFIED_OWA:
|
|
382
|
+
return self.__get_class_q_owa(c)
|
|
355
383
|
cls = OWLClass(self.iri(str(c)))
|
|
356
384
|
self.ontology.add_axiom(OWLDeclaration(cls))
|
|
357
385
|
return cls
|
|
@@ -375,16 +403,33 @@ class FuzzydlToOwl2:
|
|
|
375
403
|
curr_concept: HasWeightedConceptsInterface = type_cast[c.type](c)
|
|
376
404
|
c3: OWLClassExpression = self.get_new_atomic_class(str(curr_concept))
|
|
377
405
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
f'\t<{FuzzyOWL2Keyword.CONCEPT.get_tag_name()} {FuzzyOWL2Keyword.TYPE.get_str_value()}="{type_dict[c.type]}">\n ',
|
|
381
|
-
)
|
|
406
|
+
main_xml = FuzzyXML.build_main_xml(FuzzyOWL2Keyword.CONCEPT.get_str_value())
|
|
407
|
+
concept_xml = FuzzyXML.build_concept_xml(type_dict[c.type])
|
|
382
408
|
for i in range(len(curr_concept.concepts)):
|
|
383
409
|
c5: OWLClassExpression = self.get_base(curr_concept.concepts[i])
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
410
|
+
sub_concept_xml = FuzzyXML.build_concept_xml(
|
|
411
|
+
FuzzyOWL2Keyword.WEIGHTED.get_str_value(),
|
|
412
|
+
{
|
|
413
|
+
FuzzyOWL2Keyword.DEGREE_VALUE.get_str_value(): str(
|
|
414
|
+
curr_concept.weights[i]
|
|
415
|
+
),
|
|
416
|
+
FuzzyOWL2Keyword.BASE.get_str_value(): str(c5),
|
|
417
|
+
},
|
|
418
|
+
)
|
|
419
|
+
concept_xml.append(sub_concept_xml)
|
|
420
|
+
main_xml.append(concept_xml)
|
|
421
|
+
annotation: str = FuzzyXML.to_str(main_xml)
|
|
422
|
+
|
|
423
|
+
# annotation: str = (
|
|
424
|
+
# f'<{FuzzyOWL2Keyword.FUZZY_OWL_2.get_str_value()} {FuzzyOWL2Keyword.FUZZY_TYPE.get_str_value()}="{FuzzyOWL2Keyword.CONCEPT.get_str_value()}">\n',
|
|
425
|
+
# f'\t<{FuzzyOWL2Keyword.CONCEPT.get_tag_name()} {FuzzyOWL2Keyword.TYPE.get_str_value()}="{type_dict[c.type]}">\n ',
|
|
426
|
+
# )
|
|
427
|
+
# for i in range(len(curr_concept.concepts)):
|
|
428
|
+
# c5: OWLClassExpression = self.get_base(curr_concept.concepts[i])
|
|
429
|
+
# annotation += f'\t\t<{FuzzyOWL2Keyword.CONCEPT.get_tag_name()} {FuzzyOWL2Keyword.TYPE.get_str_value()}="{FuzzyOWL2Keyword.WEIGHTED.get_str_value()}" {FuzzyOWL2Keyword.DEGREE_VALUE.get_str_value()}="{curr_concept.weights[i]}" {FuzzyOWL2Keyword.BASE.get_str_value()}="{c5}" />\n'
|
|
430
|
+
# annotation: str = (
|
|
431
|
+
# f"\t</{FuzzyOWL2Keyword.CONCEPT.get_tag_name()} >\n</{FuzzyOWL2Keyword.FUZZY_OWL_2.get_str_value()} >"
|
|
432
|
+
# )
|
|
388
433
|
self.add_entity_annotation(annotation, c3)
|
|
389
434
|
return c3
|
|
390
435
|
|
|
@@ -392,14 +437,14 @@ class FuzzydlToOwl2:
|
|
|
392
437
|
"""Get the class for OWA, Quantified OWA, Choquet Integral, Sugeno Integral, or Quasi Sugeno Integral"""
|
|
393
438
|
type_dict: dict[ConceptType, str] = {
|
|
394
439
|
ConceptType.OWA: FuzzyOWL2Keyword.OWA.get_str_value(),
|
|
395
|
-
ConceptType.QUANTIFIED_OWA: FuzzyOWL2Keyword.Q_OWA.get_str_value(),
|
|
440
|
+
# ConceptType.QUANTIFIED_OWA: FuzzyOWL2Keyword.Q_OWA.get_str_value(),
|
|
396
441
|
ConceptType.CHOQUET_INTEGRAL: FuzzyOWL2Keyword.CHOQUET.get_str_value(),
|
|
397
442
|
ConceptType.SUGENO_INTEGRAL: FuzzyOWL2Keyword.SUGENO.get_str_value(),
|
|
398
443
|
ConceptType.QUASI_SUGENO_INTEGRAL: FuzzyOWL2Keyword.QUASI_SUGENO.get_str_value(),
|
|
399
444
|
}
|
|
400
445
|
type_cast: dict[ConceptType, typing.Callable] = {
|
|
401
446
|
ConceptType.OWA: partial(typing.cast, OwaConcept),
|
|
402
|
-
ConceptType.QUANTIFIED_OWA: partial(typing.cast, QowaConcept),
|
|
447
|
+
# ConceptType.QUANTIFIED_OWA: partial(typing.cast, QowaConcept),
|
|
403
448
|
ConceptType.CHOQUET_INTEGRAL: partial(typing.cast, ChoquetIntegral),
|
|
404
449
|
ConceptType.SUGENO_INTEGRAL: partial(typing.cast, SugenoIntegral),
|
|
405
450
|
ConceptType.QUASI_SUGENO_INTEGRAL: partial(typing.cast, QsugenoIntegral),
|
|
@@ -408,18 +453,67 @@ class FuzzydlToOwl2:
|
|
|
408
453
|
return None
|
|
409
454
|
curr_concept: HasWeightedConceptsInterface = type_cast[c.type](c)
|
|
410
455
|
c4: OWLClassExpression = self.get_new_atomic_class(str(c))
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
456
|
+
|
|
457
|
+
main_xml = FuzzyXML.build_main_xml(FuzzyOWL2Keyword.CONCEPT.get_str_value())
|
|
458
|
+
concept_xml = FuzzyXML.build_concept_xml(type_dict[c.type])
|
|
459
|
+
weights_xml = FuzzyXML.build_weights_xml(curr_concept.weights)
|
|
460
|
+
names_xml = FuzzyXML.build_names_xml(
|
|
461
|
+
[self.get_base(ci) for ci in curr_concept.concepts]
|
|
462
|
+
)
|
|
463
|
+
concept_xml.append(weights_xml)
|
|
464
|
+
concept_xml.append(names_xml)
|
|
465
|
+
main_xml.append(concept_xml)
|
|
466
|
+
annotation: str = FuzzyXML.to_str(main_xml)
|
|
467
|
+
|
|
468
|
+
# annotation: str = (
|
|
469
|
+
# f'<{FuzzyOWL2Keyword.FUZZY_OWL_2.get_str_value()} {FuzzyOWL2Keyword.FUZZY_TYPE.get_str_value()}="{FuzzyOWL2Keyword.CONCEPT.get_str_value()}">\n',
|
|
470
|
+
# f'\t<{FuzzyOWL2Keyword.CONCEPT.get_tag_name()} {FuzzyOWL2Keyword.TYPE.get_str_value()}="{type_dict[c.type]}">\n',
|
|
471
|
+
# f"\t\t<{FuzzyOWL2Keyword.WEIGHTS.get_tag_name()}>\n",
|
|
472
|
+
# )
|
|
473
|
+
# for d in curr_concept.weights:
|
|
474
|
+
# annotation += f"\t\t\t<{FuzzyOWL2Keyword.WEIGHT.get_tag_name()}>{d}</{FuzzyOWL2Keyword.WEIGHT.get_tag_name()}>\n"
|
|
475
|
+
# annotation += f"\t\t</{FuzzyOWL2Keyword.WEIGHTS.get_tag_name()}>\n\t\t<{FuzzyOWL2Keyword.CONCEPT_NAMES.get_tag_name()}>\n"
|
|
476
|
+
# for ci in curr_concept.concepts:
|
|
477
|
+
# c5: OWLClassExpression = self.get_base(ci)
|
|
478
|
+
# annotation += f"\t\t\t<{FuzzyOWL2Keyword.NAME.get_tag_name()}>{c5}</{FuzzyOWL2Keyword.NAME.get_tag_name()}>\n"
|
|
479
|
+
# annotation += f"\t\t</{FuzzyOWL2Keyword.CONCEPT_NAMES.get_tag_name()}>\n\t</{FuzzyOWL2Keyword.CONCEPT.get_tag_name()}>\n</{FuzzyOWL2Keyword.FUZZY_OWL_2.get_str_value()}>"
|
|
480
|
+
|
|
481
|
+
self.add_entity_annotation(annotation, c4)
|
|
482
|
+
return c4
|
|
483
|
+
|
|
484
|
+
def __get_class_q_owa(self, c: Concept) -> OWLClassExpression:
|
|
485
|
+
"""Get the class for OWA, Quantified OWA, Choquet Integral, Sugeno Integral, or Quasi Sugeno Integral"""
|
|
486
|
+
type_dict: dict[ConceptType, str] = {
|
|
487
|
+
ConceptType.QUANTIFIED_OWA: FuzzyOWL2Keyword.Q_OWA.get_str_value(),
|
|
488
|
+
}
|
|
489
|
+
type_cast: dict[ConceptType, typing.Callable] = {
|
|
490
|
+
ConceptType.QUANTIFIED_OWA: partial(typing.cast, QowaConcept),
|
|
491
|
+
}
|
|
492
|
+
if c.type not in type_dict:
|
|
493
|
+
return None
|
|
494
|
+
curr_concept: QowaConcept = type_cast[c.type](c)
|
|
495
|
+
c4: OWLClassExpression = self.get_new_atomic_class(str(c))
|
|
496
|
+
|
|
497
|
+
main_xml = FuzzyXML.build_main_xml(FuzzyOWL2Keyword.CONCEPT.get_str_value())
|
|
498
|
+
concept_xml = FuzzyXML.build_concept_xml(
|
|
499
|
+
type_dict[c.type],
|
|
500
|
+
{FuzzyOWL2Keyword.QUANTIFIER.get_str_value(): str(curr_concept.quantifier)},
|
|
501
|
+
)
|
|
502
|
+
names_xml = FuzzyXML.build_names_xml(
|
|
503
|
+
[self.get_base(ci) for ci in curr_concept.concepts]
|
|
415
504
|
)
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
annotation
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
505
|
+
concept_xml.append(names_xml)
|
|
506
|
+
main_xml.append(concept_xml)
|
|
507
|
+
annotation: str = FuzzyXML.to_str(main_xml)
|
|
508
|
+
# annotation: str = (
|
|
509
|
+
# f'<{FuzzyOWL2Keyword.FUZZY_OWL_2.get_str_value()} {FuzzyOWL2Keyword.FUZZY_TYPE.get_str_value()}="{FuzzyOWL2Keyword.CONCEPT.get_str_value()}">\n',
|
|
510
|
+
# f'\t<{FuzzyOWL2Keyword.CONCEPT.get_tag_name()} {FuzzyOWL2Keyword.TYPE.get_str_value()}="{type_dict[c.type]}" {FuzzyOWL2Keyword.QUANTIFIER.get_str_value()}="{curr_concept.quantifier}">\n',
|
|
511
|
+
# f"\t\t<{FuzzyOWL2Keyword.CONCEPT_NAMES.get_tag_name()}>\n",
|
|
512
|
+
# )
|
|
513
|
+
# for ci in curr_concept.concepts:
|
|
514
|
+
# c5: OWLClassExpression = self.get_base(ci)
|
|
515
|
+
# annotation += f"\t\t\t<{FuzzyOWL2Keyword.NAME.get_tag_name()}>{c5}</{FuzzyOWL2Keyword.NAME.get_tag_name()}>\n"
|
|
516
|
+
# annotation += f"\t\t</{FuzzyOWL2Keyword.CONCEPT_NAMES.get_tag_name()}>\n\t</{FuzzyOWL2Keyword.CONCEPT.get_tag_name()}>\n</{FuzzyOWL2Keyword.FUZZY_OWL_2.get_str_value()}>"
|
|
423
517
|
self.add_entity_annotation(annotation, c4)
|
|
424
518
|
return c4
|
|
425
519
|
|
|
@@ -522,11 +616,16 @@ class FuzzydlToOwl2:
|
|
|
522
616
|
elif isinstance(value, DegreeNumeric): # Degree object
|
|
523
617
|
n = value.get_numerical_value()
|
|
524
618
|
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
619
|
+
main_xml = FuzzyXML.build_main_xml(FuzzyOWL2Keyword.AXIOM.get_str_value())
|
|
620
|
+
degree_xml = FuzzyXML.build_degree_xml(n)
|
|
621
|
+
main_xml.append(degree_xml)
|
|
622
|
+
annotation_text: str = FuzzyXML.to_str(main_xml)
|
|
623
|
+
|
|
624
|
+
# annotation_text: str = (
|
|
625
|
+
# f'<{FuzzyOWL2Keyword.FUZZY_OWL_2.get_str_value()} {FuzzyOWL2Keyword.FUZZY_TYPE.get_str_value()}="{FuzzyOWL2Keyword.AXIOM.get_str_value()}">\n'
|
|
626
|
+
# f'\t<{FuzzyOWL2Keyword.DEGREE_DEF.get_tag_name()} {FuzzyOWL2Keyword.DEGREE_VALUE.get_str_value()}="{n}"/>\n'
|
|
627
|
+
# f"</{FuzzyOWL2Keyword.FUZZY_OWL_2.get_str_value()}>"
|
|
628
|
+
# )
|
|
530
629
|
annotation: OWLAnnotation = self.to_owl_annotation(annotation_text)
|
|
531
630
|
return set([annotation])
|
|
532
631
|
|
|
@@ -563,11 +662,17 @@ class FuzzydlToOwl2:
|
|
|
563
662
|
logic = str(constants.KNOWLEDGE_BASE_SEMANTICS)
|
|
564
663
|
|
|
565
664
|
if logic:
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
f'\t<{FuzzyOWL2Keyword.FUZZY_LOGIC.get_tag_name()} {FuzzyOWL2Keyword.LOGIC.get_str_value()}="{logic}" />\n'
|
|
569
|
-
f"</{FuzzyOWL2Keyword.FUZZY_OWL_2.get_str_value()}>"
|
|
665
|
+
main_xml = FuzzyXML.build_main_xml(
|
|
666
|
+
FuzzyOWL2Keyword.ONTOLOGY.get_str_value()
|
|
570
667
|
)
|
|
668
|
+
logic_xml = FuzzyXML.build_logic_xml(logic)
|
|
669
|
+
main_xml.append(logic_xml)
|
|
670
|
+
annotation: str = FuzzyXML.to_str(main_xml)
|
|
671
|
+
# annotation: str = (
|
|
672
|
+
# f'<{FuzzyOWL2Keyword.FUZZY_OWL_2.get_str_value()} {FuzzyOWL2Keyword.FUZZY_TYPE.get_str_value()}="{FuzzyOWL2Keyword.ONTOLOGY.get_str_value()}">\n'
|
|
673
|
+
# f'\t<{FuzzyOWL2Keyword.FUZZY_LOGIC.get_tag_name()} {FuzzyOWL2Keyword.LOGIC.get_str_value()}="{logic}" />\n'
|
|
674
|
+
# f"</{FuzzyOWL2Keyword.FUZZY_OWL_2.get_str_value()}>"
|
|
675
|
+
# )
|
|
571
676
|
self.add_ontology_annotation(annotation)
|
|
572
677
|
|
|
573
678
|
# Process concrete concepts
|
|
@@ -786,7 +891,8 @@ class FuzzydlToOwl2:
|
|
|
786
891
|
current_datatype: OWLDatatype = OWLDatatype(self.iri(c))
|
|
787
892
|
self.datatypes[str(c)] = current_datatype
|
|
788
893
|
|
|
789
|
-
specific: str = self._get_concrete_concept_specifics(c)
|
|
894
|
+
# specific: str = self._get_concrete_concept_specifics(c)
|
|
895
|
+
specific: tuple[str, dict[str, str]] = self._get_concrete_concept_specifics(c)
|
|
790
896
|
|
|
791
897
|
int_datatype: OWLDatatype = OWLDatatype(XSD.integer)
|
|
792
898
|
greater_than: OWLDatatypeRestriction = OWLDatatypeRestriction(
|
|
@@ -816,45 +922,102 @@ class FuzzydlToOwl2:
|
|
|
816
922
|
self.ontology.add_axiom(OWLDeclaration(current_datatype))
|
|
817
923
|
self.ontology.add_axiom(definition)
|
|
818
924
|
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
925
|
+
main_xml = FuzzyXML.build_main_xml(FuzzyOWL2Keyword.DATATYPE.get_str_value())
|
|
926
|
+
datatype_xml = FuzzyXML.build_datatype_xml(specific[0], specific[1])
|
|
927
|
+
main_xml.append(datatype_xml)
|
|
928
|
+
annotation: str = FuzzyXML.to_str(main_xml)
|
|
929
|
+
|
|
930
|
+
# annotation: str = (
|
|
931
|
+
# f'<{FuzzyOWL2Keyword.FUZZY_OWL_2.get_str_value()} {FuzzyOWL2Keyword.FUZZY_TYPE.get_str_value()}="{FuzzyOWL2Keyword.DATATYPE.get_str_value()}">\n'
|
|
932
|
+
# f'\t<{FuzzyOWL2Keyword.DATATYPE.get_tag_name()} {FuzzyOWL2Keyword.TYPE.get_str_value()}="{specific}"/>\n'
|
|
933
|
+
# f"</{FuzzyOWL2Keyword.FUZZY_OWL_2.get_str_value()}>"
|
|
934
|
+
# )
|
|
824
935
|
self.add_entity_annotation(annotation, current_datatype)
|
|
825
936
|
|
|
826
|
-
def _get_concrete_concept_specifics(
|
|
937
|
+
def _get_concrete_concept_specifics(
|
|
938
|
+
self, c: FuzzyConcreteConcept
|
|
939
|
+
) -> tuple[str, dict[str, str]]:
|
|
827
940
|
"""Get concrete concept specific parameters"""
|
|
828
941
|
if isinstance(c, CrispConcreteConcept):
|
|
829
|
-
return
|
|
942
|
+
return FuzzyOWL2Keyword.CRISP.get_str_value(), {
|
|
943
|
+
FuzzyOWL2Keyword.A.get_str_value(): str(c.a),
|
|
944
|
+
FuzzyOWL2Keyword.B.get_str_value(): str(c.b),
|
|
945
|
+
}
|
|
830
946
|
elif isinstance(c, LeftConcreteConcept):
|
|
831
|
-
return
|
|
947
|
+
return FuzzyOWL2Keyword.LEFT_SHOULDER.get_str_value(), {
|
|
948
|
+
FuzzyOWL2Keyword.A.get_str_value(): str(c.a),
|
|
949
|
+
FuzzyOWL2Keyword.B.get_str_value(): str(c.b),
|
|
950
|
+
}
|
|
832
951
|
elif isinstance(c, RightConcreteConcept):
|
|
833
|
-
return
|
|
952
|
+
return FuzzyOWL2Keyword.RIGHT_SHOULDER.get_str_value(), {
|
|
953
|
+
FuzzyOWL2Keyword.A.get_str_value(): str(c.a),
|
|
954
|
+
FuzzyOWL2Keyword.B.get_str_value(): str(c.b),
|
|
955
|
+
}
|
|
834
956
|
elif isinstance(c, TriangularConcreteConcept):
|
|
835
|
-
return
|
|
957
|
+
return FuzzyOWL2Keyword.TRIANGULAR.get_str_value(), {
|
|
958
|
+
FuzzyOWL2Keyword.A.get_str_value(): str(c.a),
|
|
959
|
+
FuzzyOWL2Keyword.B.get_str_value(): str(c.b),
|
|
960
|
+
FuzzyOWL2Keyword.C.get_str_value(): str(c.c),
|
|
961
|
+
}
|
|
836
962
|
elif isinstance(c, TrapezoidalConcreteConcept):
|
|
837
|
-
return
|
|
838
|
-
|
|
963
|
+
return FuzzyOWL2Keyword.TRAPEZOIDAL.get_str_value(), {
|
|
964
|
+
FuzzyOWL2Keyword.A.get_str_value(): str(c.a),
|
|
965
|
+
FuzzyOWL2Keyword.B.get_str_value(): str(c.b),
|
|
966
|
+
FuzzyOWL2Keyword.C.get_str_value(): str(c.c),
|
|
967
|
+
FuzzyOWL2Keyword.D.get_str_value(): str(c.d),
|
|
968
|
+
}
|
|
969
|
+
return "", dict()
|
|
970
|
+
|
|
971
|
+
# def _get_concrete_concept_specifics(self, c: FuzzyConcreteConcept) -> str:
|
|
972
|
+
# """Get concrete concept specific parameters"""
|
|
973
|
+
# if isinstance(c, CrispConcreteConcept):
|
|
974
|
+
# return f'{FuzzyOWL2Keyword.CRISP.get_str_value()}" {FuzzyOWL2Keyword.A.get_str_value()}="{c.a}" {FuzzyOWL2Keyword.B.get_str_value()}="{c.b}'
|
|
975
|
+
# elif isinstance(c, LeftConcreteConcept):
|
|
976
|
+
# return f'{FuzzyOWL2Keyword.LEFT_SHOULDER.get_str_value()}" {FuzzyOWL2Keyword.A.get_str_value()}="{c.a}" {FuzzyOWL2Keyword.B.get_str_value()}="{c.b}'
|
|
977
|
+
# elif isinstance(c, RightConcreteConcept):
|
|
978
|
+
# return f'{FuzzyOWL2Keyword.RIGHT_SHOULDER.get_str_value()}" {FuzzyOWL2Keyword.A.get_str_value()}="{c.a}" {FuzzyOWL2Keyword.B.get_str_value()}="{c.b}'
|
|
979
|
+
# elif isinstance(c, TriangularConcreteConcept):
|
|
980
|
+
# return f'{FuzzyOWL2Keyword.TRIANGULAR.get_str_value()}" {FuzzyOWL2Keyword.A.get_str_value()}="{c.a}" {FuzzyOWL2Keyword.B.get_str_value()}="{c.b}" {FuzzyOWL2Keyword.C.get_str_value()}="{c.c}'
|
|
981
|
+
# elif isinstance(c, TrapezoidalConcreteConcept):
|
|
982
|
+
# return f'{FuzzyOWL2Keyword.TRAPEZOIDAL.get_str_value()}" {FuzzyOWL2Keyword.A.get_str_value()}="{c.a}" {FuzzyOWL2Keyword.B.get_str_value()}="{c.b}" {FuzzyOWL2Keyword.C.get_str_value()}="{c.c}" {FuzzyOWL2Keyword.D.get_str_value()}="{c.d}'
|
|
983
|
+
# return ""
|
|
839
984
|
|
|
840
985
|
def _process_modifier(self, mod: Modifier) -> None:
|
|
841
986
|
"""Process a modifier"""
|
|
842
987
|
Util.debug(f"Process modifier -> {mod}")
|
|
988
|
+
|
|
989
|
+
main_xml = FuzzyXML.build_main_xml(FuzzyOWL2Keyword.MODIFIER.get_str_value())
|
|
990
|
+
|
|
843
991
|
if isinstance(mod, LinearModifier):
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
f"</{FuzzyOWL2Keyword.FUZZY_OWL_2.get_str_value()}>"
|
|
992
|
+
modifier_xml = FuzzyXML.build_modifier_xml(
|
|
993
|
+
FuzzyOWL2Keyword.LINEAR.get_str_value(),
|
|
994
|
+
{FuzzyOWL2Keyword.C.get_str_value(): str(mod.c)},
|
|
848
995
|
)
|
|
996
|
+
# annotation: str = (
|
|
997
|
+
# f'<{FuzzyOWL2Keyword.FUZZY_OWL_2.get_str_value()} {FuzzyOWL2Keyword.FUZZY_TYPE.get_str_value()}="{FuzzyOWL2Keyword.MODIFIER.get_str_value()}">\n'
|
|
998
|
+
# f'\t<{FuzzyOWL2Keyword.MODIFIER.get_tag_name()} {FuzzyOWL2Keyword.TYPE.get_str_value()}="{FuzzyOWL2Keyword.LINEAR.get_str_value()}" {FuzzyOWL2Keyword.C.get_str_value()}="{mod.c}"/>\n'
|
|
999
|
+
# f"</{FuzzyOWL2Keyword.FUZZY_OWL_2.get_str_value()}>"
|
|
1000
|
+
# )
|
|
849
1001
|
elif isinstance(mod, TriangularModifier):
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
1002
|
+
modifier_xml = FuzzyXML.build_modifier_xml(
|
|
1003
|
+
FuzzyOWL2Keyword.TRIANGULAR.get_str_value(),
|
|
1004
|
+
{
|
|
1005
|
+
FuzzyOWL2Keyword.A.get_str_value(): str(mod.a),
|
|
1006
|
+
FuzzyOWL2Keyword.B.get_str_value(): str(mod.b),
|
|
1007
|
+
FuzzyOWL2Keyword.C.get_str_value(): str(mod.c),
|
|
1008
|
+
},
|
|
854
1009
|
)
|
|
1010
|
+
# annotation: str = (
|
|
1011
|
+
# f'<{FuzzyOWL2Keyword.FUZZY_OWL_2.get_str_value()} {FuzzyOWL2Keyword.FUZZY_TYPE.get_str_value()}="{FuzzyOWL2Keyword.MODIFIER.get_str_value()}">\n'
|
|
1012
|
+
# f'\t<{FuzzyOWL2Keyword.MODIFIER.get_tag_name()} {FuzzyOWL2Keyword.TYPE.get_str_value()}="{FuzzyOWL2Keyword.TRIANGULAR.get_str_value()}" {FuzzyOWL2Keyword.A.get_str_value()}="{mod.a}" {FuzzyOWL2Keyword.B.get_str_value()}="{mod.b}" {FuzzyOWL2Keyword.C.get_str_value()}="{mod.c}"/>\n'
|
|
1013
|
+
# f"</{FuzzyOWL2Keyword.FUZZY_OWL_2.get_str_value()}>"
|
|
1014
|
+
# )
|
|
855
1015
|
else:
|
|
856
1016
|
raise ValueError(f"Unknown modifier type: {type(mod)}")
|
|
857
1017
|
|
|
1018
|
+
main_xml.append(modifier_xml)
|
|
1019
|
+
annotation: str = FuzzyXML.to_str(main_xml)
|
|
1020
|
+
|
|
858
1021
|
current_datatype: OWLDatatype = OWLDatatype(self.iri(mod))
|
|
859
1022
|
self.modifiers[str(mod)] = current_datatype
|
|
860
1023
|
self.ontology.add_axiom(OWLDeclaration(current_datatype))
|
|
@@ -35,7 +35,7 @@ from fuzzy_dl_owl2.fuzzyowl2.owl_types.weighted_sum_concept import WeightedSumCo
|
|
|
35
35
|
from fuzzy_dl_owl2.fuzzyowl2.owl_types.weighted_sum_zero_concept import (
|
|
36
36
|
WeightedSumZeroConcept,
|
|
37
37
|
)
|
|
38
|
-
from fuzzy_dl_owl2.fuzzyowl2.parser.
|
|
38
|
+
from fuzzy_dl_owl2.fuzzyowl2.parser.owl2_xml_parser import FuzzyOwl2XMLParser
|
|
39
39
|
from pyowl2.abstracts.annotation_value import OWLAnnotationValue
|
|
40
40
|
from pyowl2.abstracts.axiom import OWLAxiom
|
|
41
41
|
from pyowl2.abstracts.class_expression import OWLClassExpression
|
|
@@ -166,7 +166,7 @@ class FuzzyOwl2(object):
|
|
|
166
166
|
self.processed_axioms: set[str] = set()
|
|
167
167
|
self.ontologies: set[OWLOntology] = set()
|
|
168
168
|
|
|
169
|
-
|
|
169
|
+
FuzzyOwl2XMLParser.load_config()
|
|
170
170
|
|
|
171
171
|
self.ontology_path = input_file
|
|
172
172
|
self.ontology_iri = IRI(Namespace(base_iri))
|
|
@@ -200,9 +200,13 @@ class FuzzyOwl2(object):
|
|
|
200
200
|
if annotation.annotation_property != self.fuzzy_label:
|
|
201
201
|
continue
|
|
202
202
|
value: OWLAnnotationValue = annotation.annotation_value
|
|
203
|
-
annotation_str: str = str(value)
|
|
203
|
+
annotation_str: str = str(value)
|
|
204
204
|
Util.debug(f"Annotation for ontology -> {annotation_str}")
|
|
205
|
-
|
|
205
|
+
logic: typing.Optional[str] = FuzzyOwl2XMLParser.parse_string(
|
|
206
|
+
annotation_str
|
|
207
|
+
)
|
|
208
|
+
Util.debug(f"Parsed annotation -> {logic}")
|
|
209
|
+
self.write_fuzzy_logic(logic)
|
|
206
210
|
|
|
207
211
|
def __get_facets(self, name: str) -> list[float]:
|
|
208
212
|
facets: list[float] = [float("-inf"), float("inf")]
|
|
@@ -282,13 +286,14 @@ class FuzzyOwl2(object):
|
|
|
282
286
|
f"Error: There are {len(annotations)} datatype annotations for {datatype}"
|
|
283
287
|
)
|
|
284
288
|
annotation: OWLAnnotation = list(annotations)[0].annotation_value
|
|
285
|
-
annotation_str: str = str(annotation)
|
|
289
|
+
annotation_str: str = str(annotation)
|
|
286
290
|
Util.debug(f"Annotation for {datatype} -> {annotation_str}")
|
|
287
291
|
datatype_name: str = self.get_short_name(datatype)
|
|
288
292
|
facets: list[OWLFacet] = self.__get_facets(datatype_name)
|
|
289
293
|
c: typing.Union[ConceptDefinition, FuzzyModifier] = (
|
|
290
|
-
|
|
294
|
+
FuzzyOwl2XMLParser.parse_string(annotation_str)
|
|
291
295
|
)
|
|
296
|
+
Util.debug(f"Parsed annotation -> {c}")
|
|
292
297
|
if isinstance(c, FuzzyDatatype):
|
|
293
298
|
c.set_min_value(facets[0])
|
|
294
299
|
c.set_max_value(facets[1])
|
|
@@ -330,12 +335,12 @@ class FuzzyOwl2(object):
|
|
|
330
335
|
f"Error: There are {len(annotations)} class annotations for {cls}"
|
|
331
336
|
)
|
|
332
337
|
annotation: OWLAnnotation = list(annotations)[0].annotation_value
|
|
333
|
-
annotation_str: str = str(annotation)
|
|
338
|
+
annotation_str: str = str(annotation)
|
|
334
339
|
Util.debug(f"Annotation for concept {cls} -> {annotation_str}")
|
|
335
|
-
concept: ConceptDefinition =
|
|
340
|
+
concept: ConceptDefinition = FuzzyOwl2XMLParser.parse_string(
|
|
336
341
|
annotation_str
|
|
337
|
-
)
|
|
338
|
-
Util.debug(f"
|
|
342
|
+
)
|
|
343
|
+
Util.debug(f"Parsed annotation -> {concept}")
|
|
339
344
|
name: str = self.get_short_name(cls)
|
|
340
345
|
if isinstance(concept, ModifiedConcept):
|
|
341
346
|
mod_name: str = concept.get_fuzzy_modifier()
|
|
@@ -401,11 +406,12 @@ class FuzzyOwl2(object):
|
|
|
401
406
|
f"Error: There are {len(annotations)} property annotations for {property}"
|
|
402
407
|
)
|
|
403
408
|
annotation: OWLAnnotation = list(annotations)[0].annotation_value
|
|
404
|
-
annotation_str: str = str(annotation)
|
|
409
|
+
annotation_str: str = str(annotation)
|
|
405
410
|
Util.debug(f"Annotation for property {property} -> {annotation_str}")
|
|
406
411
|
prop: typing.Optional[ModifiedProperty] = (
|
|
407
|
-
|
|
408
|
-
)
|
|
412
|
+
FuzzyOwl2XMLParser.parse_string(annotation_str)
|
|
413
|
+
)
|
|
414
|
+
Util.debug(f"Parsed annotation -> {prop}")
|
|
409
415
|
if prop is None:
|
|
410
416
|
return
|
|
411
417
|
if not isinstance(prop, ModifiedProperty):
|
|
@@ -428,10 +434,10 @@ class FuzzyOwl2(object):
|
|
|
428
434
|
f"Error: There are {len(annotations)} annotations for axiom {axiom}."
|
|
429
435
|
)
|
|
430
436
|
annotation: OWLAnnotation = list(annotations)[0].annotation_value
|
|
431
|
-
annotation_str: str = str(annotation)
|
|
437
|
+
annotation_str: str = str(annotation)
|
|
432
438
|
Util.debug(f"Annotation for degree -> {annotation_str}")
|
|
433
|
-
deg: float =
|
|
434
|
-
Util.debug(f"
|
|
439
|
+
deg: float = FuzzyOwl2XMLParser.parse_string(annotation_str)
|
|
440
|
+
Util.debug(f"Parsed annotation -> {deg}")
|
|
435
441
|
if not isinstance(deg, constants.NUMBER):
|
|
436
442
|
raise ValueError
|
|
437
443
|
return deg
|
|
@@ -48,7 +48,6 @@ from pyowl2.expressions.data_property import OWLDataProperty
|
|
|
48
48
|
from pyowl2.expressions.object_property import OWLObjectProperty
|
|
49
49
|
from pyowl2.individual.anonymous_individual import OWLAnonymousIndividual
|
|
50
50
|
from pyowl2.literal.literal import OWLLiteral
|
|
51
|
-
from pyowl2.utils import utils
|
|
52
51
|
|
|
53
52
|
|
|
54
53
|
# @utils.timer_decorator
|
|
@@ -608,7 +607,7 @@ class FuzzyOwl2ToFuzzyDL(FuzzyOwl2):
|
|
|
608
607
|
d: float,
|
|
609
608
|
) -> None:
|
|
610
609
|
self.__write(
|
|
611
|
-
f"(implies-role {self.
|
|
610
|
+
f"(implies-role {self.get_data_property_name(subproperty)} {self.get_data_property_name(superproperty)} {d})"
|
|
612
611
|
)
|
|
613
612
|
|
|
614
613
|
def write_sub_property_chain_of_axiom(
|
|
@@ -635,9 +634,9 @@ class FuzzyOwl2ToFuzzyDL(FuzzyOwl2):
|
|
|
635
634
|
self, class_set: set[OWLDataPropertyExpression]
|
|
636
635
|
) -> None:
|
|
637
636
|
first: OWLDataPropertyExpression = next(class_set)
|
|
638
|
-
first_name: str = self.
|
|
637
|
+
first_name: str = self.get_data_property_name(first)
|
|
639
638
|
for property in class_set - set([first]):
|
|
640
|
-
property_name: str = self.
|
|
639
|
+
property_name: str = self.get_data_property_name(property)
|
|
641
640
|
self.__write(f"(implies-role {first_name} {property_name})")
|
|
642
641
|
self.__write(f"(implies-role {property_name} {first_name})")
|
|
643
642
|
|
|
@@ -4,7 +4,7 @@ from fuzzy_dl_owl2.fuzzyowl2.owl_types.fuzzy_property import FuzzyProperty
|
|
|
4
4
|
class ModifiedProperty(FuzzyProperty):
|
|
5
5
|
|
|
6
6
|
def __init__(self, mod: str, prop: str) -> None:
|
|
7
|
-
super.__init__()
|
|
7
|
+
super().__init__()
|
|
8
8
|
self._mod: str = mod
|
|
9
9
|
self._prop: str = prop
|
|
10
10
|
|
|
@@ -13,3 +13,9 @@ class ModifiedProperty(FuzzyProperty):
|
|
|
13
13
|
|
|
14
14
|
def get_property(self) -> str:
|
|
15
15
|
return self._prop
|
|
16
|
+
|
|
17
|
+
def __repr__(self) -> str:
|
|
18
|
+
return str(self)
|
|
19
|
+
|
|
20
|
+
def __str__(self) -> str:
|
|
21
|
+
return f"({self.get_fuzzy_modifier()}, {self.get_property()})"
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
from .owl2_parser import *
|
|
1
|
+
# from .owl2_parser import *
|
|
2
|
+
from .owl2_xml_parser import *
|