mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-12 06:42:11 +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):
|
def from_value(x):
|
||||||
"""Convert Uri or Literal to schema Term."""
|
"""Convert Uri, Literal, or string to schema Term."""
|
||||||
if x is None:
|
if x is None:
|
||||||
return None
|
return None
|
||||||
if isinstance(x, Uri):
|
if isinstance(x, Uri):
|
||||||
return Term(type=IRI, iri=str(x))
|
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:
|
else:
|
||||||
return Term(type=LITERAL, value=str(x))
|
return Term(type=LITERAL, value=str(x))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,25 @@ import logging
|
||||||
import time
|
import time
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
|
from ... schema import IRI, LITERAL
|
||||||
|
|
||||||
# Module logger
|
# Module logger
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
LABEL="http://www.w3.org/2000/01/rdf-schema#label"
|
LABEL="http://www.w3.org/2000/01/rdf-schema#label"
|
||||||
|
|
||||||
|
|
||||||
|
def term_to_string(term):
|
||||||
|
"""Extract string value from a Term object."""
|
||||||
|
if term is None:
|
||||||
|
return None
|
||||||
|
if term.type == IRI:
|
||||||
|
return term.iri
|
||||||
|
elif term.type == LITERAL:
|
||||||
|
return term.value
|
||||||
|
# Fallback
|
||||||
|
return term.iri or term.value or str(term)
|
||||||
|
|
||||||
class LRUCacheWithTTL:
|
class LRUCacheWithTTL:
|
||||||
"""LRU cache with TTL for label caching
|
"""LRU cache with TTL for label caching
|
||||||
|
|
||||||
|
|
@ -93,7 +107,7 @@ class Query:
|
||||||
)
|
)
|
||||||
|
|
||||||
entities = [
|
entities = [
|
||||||
str(e.entity)
|
term_to_string(e.entity)
|
||||||
for e in entity_matches
|
for e in entity_matches
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue