mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-09 05:12:12 +02:00
Fixed triples
This commit is contained in:
parent
1fb5782c2f
commit
36c84fe6bc
2 changed files with 24 additions and 2 deletions
|
|
@ -22,11 +22,19 @@ def to_value(x):
|
|||
|
||||
|
||||
def from_value(x):
|
||||
"""Convert Uri or Literal to schema Term."""
|
||||
"""Convert Uri, Literal, or string to schema Term."""
|
||||
if x is None:
|
||||
return None
|
||||
if isinstance(x, Uri):
|
||||
return Term(type=IRI, iri=str(x))
|
||||
elif isinstance(x, Literal):
|
||||
return Term(type=LITERAL, value=str(x))
|
||||
elif isinstance(x, str):
|
||||
# Detect IRIs by common prefixes
|
||||
if x.startswith("http://") or x.startswith("https://") or x.startswith("urn:"):
|
||||
return Term(type=IRI, iri=x)
|
||||
else:
|
||||
return Term(type=LITERAL, value=x)
|
||||
else:
|
||||
return Term(type=LITERAL, value=str(x))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue