Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented entities_metadata_statements() for SQLImplementation() #679

Merged
merged 13 commits into from
Nov 16, 2023
24 changes: 24 additions & 0 deletions src/oaklib/implementations/sqldb/sql_implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
DEFINITION,
LANGUAGE_TAG,
METADATA_MAP,
METADATA_STATEMENT,
PRED_CURIE,
PREFIX_MAP,
RELATIONSHIP,
Expand Down Expand Up @@ -671,6 +672,29 @@ def entity_metadata_map(self, curie: CURIE, include_all_triples=False) -> METADA
self.add_missing_property_values(curie, m)
return dict(m)

def entities_metadata_statements(
self, curies: Iterable[CURIE], predicates: Optional[List[PRED_CURIE]] = None
) -> Iterator[METADATA_STATEMENT]:
q = self.session.query(Statements)
# if not include_all_triples:
# subquery = self.session.query(RdfTypeStatement.subject).filter(
# RdfTypeStatement.object == "owl:AnnotationProperty"
# )
# annotation_properties = {row.subject for row in subquery}
# annotation_properties = annotation_properties.union(STANDARD_ANNOTATION_PROPERTIES)
# q = q.filter(Statements.predicate.in_(tuple(annotation_properties)))
q = q.filter(Statements.subject.in_(curies))
if predicates is not None:
q = q.filter(Statements.predicate.in_(predicates))
for row in q:
if row.value is not None:
v = _python_value(row.value, row.datatype)
elif row.object is not None:
v = row.object
else:
v = None
yield row.subject, row.predicate, v, row.datatype, {}
hrshdhgd marked this conversation as resolved.
Show resolved Hide resolved

def ontologies(self) -> Iterable[CURIE]:
for row in self.session.query(OntologyNode):
yield row.id
Expand Down
10 changes: 10 additions & 0 deletions tests/test_implementations/test_sqldb.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
HAS_PART,
IS_A,
LABEL_PREDICATE,
OIO_CREATION_DATE,
PART_OF,
RDF_TYPE,
)
Expand All @@ -39,6 +40,7 @@
HUMAN,
IMBO,
INPUT_DIR,
MEMBRANE,
NUCLEAR_ENVELOPE,
NUCLEUS,
OUTPUT_DIR,
Expand Down Expand Up @@ -899,3 +901,11 @@ def test_transitive_object_properties(self):

def test_simple_subproperty_of_chains(self):
self.compliance_tester.test_simple_subproperty_of_chains(self.oi)

def test_entities_metadata_statements(self):
hrshdhgd marked this conversation as resolved.
Show resolved Hide resolved
curies = [MEMBRANE]
predicates = [OIO_CREATION_DATE]
oi = self.oi
result = list(oi.entities_metadata_statements(curies=curies, predicates=predicates))
self.assertEqual(len(result), 1)
self.assertEqual(len(result[0]), 5)