Repository navigation
Integration with rdflib-sqlalchemy, oxrdflib #203
Description
Perhaps this is a Google Colab-only issue?
!pip install rdflib-sqlalchemy
import kglab
from rdflib import plugin, Graph, Literal, URIRef
from rdflib.store import Store
store = plugin.get("SQLAlchemy", Store)(identifier=URIRef("rdflib_test"))
graph = Graph(store)
graph.open(Literal("sqlite://"), create=True)
kg = kglab.KnowledgeGraph(
name = "...",
import_graph = graph
)
AttributeError Traceback (most recent call last)
in ()
---> 50 import_graph = graph
51 )3 frames
/content/gdrive/MyDrive/ONR/kglab/kglab/kglab.py in init(self, name, base_uri, language, use_gpus, import_graph, namespaces)
111
112 # import relations from another RDF graph, or start from blank
--> 113 if import_graph:
114 self._g = import_graph
115 else:/usr/local/lib/python3.7/dist-packages/rdflib/graph.py in len(self)
527 return 1
528
--> 529 def eq(self, other):
530 return isinstance(other, Graph) and self.identifier == other.identifier
531/usr/local/lib/python3.7/dist-packages/rdflib_sqlalchemy/store.py in len(self, context)
205 (literal, literalContext,
206 ASSERTED_LITERAL_PARTITION), ]
--> 207 q = union_select(selects, distinct=True, select_type=COUNT_SELECT)
208 else:
209 selects = [/usr/local/lib/python3.7/dist-packages/rdflib_sqlalchemy/sql.py in union_select(select_components, distinct, select_type)
54
55 if select_type == COUNT_SELECT:
---> 56 select_clause = table.count(whereClause)
57 elif select_type == CONTEXT_SELECT:
58 select_clause = expression.select([table.c.context], whereClause)AttributeError: 'Alias' object has no attribute 'count'
And oxrdflib:
!pip install oxrdflib
import kglab
import rdflib
kg = kglab.KnowledgeGraph(
name = "...",
import_graph = rdflib.Graph(store="OxMemory")
)
ModuleNotFoundError Traceback (most recent call last)
in ()
---> 49 import_graph = rdflib.Graph(store="OxMemory")
51 )3 frames
/content/gdrive/MyDrive/ONR/kglab/kglab/kglab.py in init(self, name, base_uri, language, use_gpus, import_graph, namespaces)
114 self._g = import_graph
115 else:
--> 116 self._g = rdflib.Graph()
117
118 # initialize the namespaces/usr/local/lib/python3.7/dist-packages/rdflib/graph.py in init(self, store, identifier, namespace_manager, base)
325 if self.__namespace_manager is None:
326 self.__namespace_manager = NamespaceManager(self)
--> 327 return self.__namespace_manager
328
329 def _set_namespace_manager(self, nm):/usr/local/lib/python3.7/dist-packages/rdflib/plugin.py in get(name, kind)
108
109
--> 110 try:
111 from pkg_resources import iter_entry_points
112 except ImportError:/usr/local/lib/python3.7/dist-packages/rdflib/plugin.py in getClass(self)
69 module = import(self.module_path, globals(), locals(), [""])
70 self._class = getattr(module, self.class_name)
---> 71 return self._class
72
73ModuleNotFoundError: No module named 'rdflib.plugins.stores.memory'
Activity
ceteri commentedon Mar 19, 2022
Hi @davidshumway, thank you for reporting this. We've begun to work with
Oxrdfliband have support in v0.5.3 ofkglab:NB: note the change in the name of the store, as of
Oxrdflibv0.3.0 on 2022-03-19 https://github.com/oxigraph/oxrdflib/releases/tag/v0.3.0Pros:
Oxrdflibruns ~2 orders of magnitude faster than the defaultRDFlib.Storeimplementation.Cons:
Oxrdflibhas some troubles with namespaces ... specifically, any prefixes used in a namespace must be explicitly added to each SPARQL queryOPTIONALclausesOxrdflibusessetup.pyto register itsRDFlibplugins and it's not clear that this is working properlyWe've been able to isolate these issues with a minimum Python code + RDF + SPARQL example, and I'll be opening an issue for
Oxrdflibwhich is linked to this issue.See also: PRs #240, #241, #242
The
SQLAlchemyissues are a different matter. Ostensibly, our new support for specifying astore="foo"in theKnowledgeGraphconstructor similarly applies here. The exceptions listed seem to be in theSQLAlchemystore's support for required methods, specifically in the support for contexts. Perhaps they didn't quite get that far?FWIW, we've got a new
RDFlib.Storeplugin in development which is based onNumPy/cuNumericand it does implement the contexts support.cc: @paoespinozarias @neobernad @jelisf @Mec-iS
ceteri commentedon Mar 20, 2022
See issue oxigraph/oxrdflib#8