diff --git a/.DS_Store b/.DS_Store index c4eb021..001d2ab 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/.gitignore b/.gitignore index 68bc17f..e05e2e7 100644 --- a/.gitignore +++ b/.gitignore @@ -158,3 +158,4 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ +.DS_Store diff --git a/example.py b/example.py index a28f326..25cfecc 100644 --- a/example.py +++ b/example.py @@ -12,7 +12,7 @@ graph2 = dataset.get_named_graph("http://example.org/graph2") resource2 = graph2.create_resource() -resource2.add_property(graph2.create_property("http://example.org/property3"), graph2.create_literal("Object2")) +resource2.add_property(graph2.create_property("http://example.org/property3"), graph2.create_literal("Object2", language="da")) resource3 = graph2.create_resource("http://example.org/subject3") resource3.add_property(graph2.create_property("http://example.org/property4"), graph2.create_literal("Object3")) diff --git a/oxijen/model_impl/impl.py b/oxijen/model_impl/impl.py index 0acbc1c..cf96bb6 100644 --- a/oxijen/model_impl/impl.py +++ b/oxijen/model_impl/impl.py @@ -63,23 +63,26 @@ def create_resource(self, uri: Optional[str] = None) -> Resource: def create_property(self, uri: str) -> Property: return ResourceImpl(NamedNode(uri), self) - def create_literal(self, value: str) -> Literal: - return Literal(value) # should it be xsd:string-typed by default as per RDF 1.1? + def create_literal(self, value: str, language: Optional[str] = None) -> Literal: + return Literal(value, language=language) # should it be xsd:string-typed by default as per RDF 1.1? - def create_typed_literal(self, value: Any, type_uri: Optional[str] = None) -> Literal: - if type_uri is None: + def create_typed_literal(self, value: Any, datatype: Optional[Union[str, NamedNode]] = None) -> Literal: + if datatype is None: match value: case int(): - type_uri = XSD.INTEGER.value + datatype = NamedNode(XSD.INTEGER.value) case str(): - type_uri = XSD.STRING.value + datatype = NamedNode(XSD.STRING.value) case float(): - type_uri = XSD.FLOAT.value + datatype = NamedNode(XSD.FLOAT.value) # TO-DO: support more types case _: raise TypeError('Unsupported type conversion') + else: + if type(datatype) is str: + datatype = NamedNode(datatype) - return Literal(str(value), datatype=NamedNode(type_uri)) + return Literal(str(value), datatype=datatype) class GraphStoreImpl(GraphImpl): @@ -105,6 +108,11 @@ def add(self, triples: Union[Iterator[Triple], 'Graph']) -> 'Graph': return self + def remove_all(self) -> 'Graph': + self.store.remove_graph(self.name) + + return self + class DatasetStoreImpl(Dataset): diff --git a/oxijen/rdf_model.py b/oxijen/rdf_model.py index cf076db..81aae46 100644 --- a/oxijen/rdf_model.py +++ b/oxijen/rdf_model.py @@ -66,11 +66,11 @@ def create_property(self, uri: str) -> Property: pass @abstractmethod - def create_literal(self, value: str) -> Literal: + def create_literal(self, value: str, language: Optional[str] = None) -> Literal: pass @abstractmethod - def create_typed_literal(self, value: Any, type_uri: Optional[str] = None) -> Literal: + def create_typed_literal(self, value: Any, datatype: Optional[Union[str, NamedNode]] = None) -> Literal: pass @abstractmethod @@ -81,6 +81,10 @@ def list_triples(self) -> Iterator[Triple]: def add(self, triples: Union[Iterator[Triple], 'Graph']) -> 'Graph': pass + @abstractmethod + def remove_all(self ) -> 'Graph': + pass + class GraphFactory: