From f6d12980262adebc63f6e8186daf77649e3f6ec2 Mon Sep 17 00:00:00 2001 From: Binh Vu Date: Thu, 4 Jan 2024 10:52:17 +0000 Subject: [PATCH] add wdentity functions to entity --- kgdata/models/entity.py | 14 +++++++++++++- pyproject.toml | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/kgdata/models/entity.py b/kgdata/models/entity.py index 16c6a2f..f809e59 100644 --- a/kgdata/models/entity.py +++ b/kgdata/models/entity.py @@ -5,7 +5,9 @@ from kgdata.misc.ntriples_parser import node_from_dict, node_to_dict from kgdata.models.multilingual import MultiLingualString, MultiLingualStringList -from rdflib import Literal, URIRef +from rdflib import RDF, Literal, URIRef + +RDF_TYPE = str(RDF.type) @dataclass @@ -53,6 +55,16 @@ def apply_redirection(self, redirection: Mapping[str, str]) -> Entity: }, ) + def get_object_prop_value(self, prop: str) -> list[str]: + lst = [] + for stmt in self.props.get(prop, []): + if isinstance(stmt.value, URIRef): + lst.append(str(stmt.value)) + return lst + + def instance_of(self, instanceof: str = RDF_TYPE): + return self.get_object_prop_value(instanceof) + @dataclass class Statement: diff --git a/pyproject.toml b/pyproject.toml index 4d15455..2d612b3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "kgdata" -version = "6.1.0" +version = "6.2.0" description = "Library to process dumps of knowledge graphs (Wikipedia, DBpedia, Wikidata)" readme = "README.md" authors = [{ name = "Binh Vu", email = "binh@toan2.com" }]