diff --git a/funowl/ontology_document.py b/funowl/ontology_document.py index a12a800..0729341 100644 --- a/funowl/ontology_document.py +++ b/funowl/ontology_document.py @@ -175,9 +175,10 @@ def objectPropertyRange(self, ope: ObjectPropertyExpression.types(), ce: ClassEx self.axioms.append(ObjectPropertyRange(ope, ce)) return self - def imports(self, import_: Union["Ontology", str]) -> "Ontology": + def imports(self, import_: Union["Ontology", "OntologyDocument", str]) -> "Ontology": self.directlyImportsDocuments.append( - Import(import_.iri if isinstance(import_, Ontology) else IRI(str(import_)))) + Import(import_.iri if isinstance(import_, Ontology) else + import_.ontology.iri if isinstance(import_, OntologyDocument) else IRI(str(import_)))) return self def namedIndividuals(self, *individuals: IRI.types()) -> "Ontology": diff --git a/funowl/prefix_declarations.py b/funowl/prefix_declarations.py index e13cb2c..804ff7d 100644 --- a/funowl/prefix_declarations.py +++ b/funowl/prefix_declarations.py @@ -1,10 +1,11 @@ from dataclasses import dataclass -from typing import Optional, List +from typing import Optional, List, Union from rdflib import Graph from rdflib.namespace import NamespaceManager, OWL from rdflib.term import URIRef +from funowl.base.cast_function import exclude from funowl.base.fun_owl_base import FunOwlBase from funowl.general_definitions import PrefixName, FullIRI from funowl.writers.FunctionalWriter import FunctionalWriter @@ -12,9 +13,13 @@ @dataclass class Prefix(FunOwlBase): - prefixName: Optional[PrefixName] + prefixName: Optional[Union[PrefixName, str]] fullIRI: FullIRI + def __post_init__(self): + if self.prefixName is not None and not isinstance(self.prefixName, PrefixName): + self.prefixName = PrefixName(self.prefixName) + def to_functional(self, w: FunctionalWriter) -> FunctionalWriter: return w.func(self, lambda: w.concat((self.prefixName or '') + ':', '=', URIRef(str(self.fullIRI)).n3(), sep=' '))