Skip to content

Commit

Permalink
Merge pull request #23 from hsolbrig/more_tweaks
Browse files Browse the repository at this point in the history
Changed the Ontology.imports signature to allow an OntologyDocument. …
  • Loading branch information
hsolbrig authored Aug 11, 2021
2 parents dc50773 + 2f3688c commit edee9e0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 3 additions & 2 deletions funowl/ontology_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
9 changes: 7 additions & 2 deletions funowl/prefix_declarations.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
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


@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=' '))
Expand Down

0 comments on commit edee9e0

Please sign in to comment.