Skip to content

Commit

Permalink
add wdentity functions to entity
Browse files Browse the repository at this point in the history
  • Loading branch information
Binh Vu committed Jan 4, 2024
1 parent a2fd3ec commit f6d1298
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 13 additions & 1 deletion kgdata/models/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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" }]
Expand Down

0 comments on commit f6d1298

Please sign in to comment.