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

Integration with rdflib-sqlalchemy, oxrdflib #203

Open
davidshumway opened this issue Oct 25, 2021 · 2 comments
Open

Integration with rdflib-sqlalchemy, oxrdflib #203

davidshumway opened this issue Oct 25, 2021 · 2 comments
Assignees
Labels
help wanted Extra attention is needed question Further information is requested

Comments

@davidshumway
Copy link

davidshumway commented Oct 25, 2021

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
73

ModuleNotFoundError: No module named 'rdflib.plugins.stores.memory'

@ceteri ceteri added help wanted Extra attention is needed question Further information is requested labels Mar 19, 2022
@ceteri ceteri self-assigned this Mar 19, 2022
@ceteri
Copy link
Collaborator

ceteri commented Mar 19, 2022

Hi @davidshumway, thank you for reporting this. We've begun to work with Oxrdflib and have support in v0.5.3 of kglab:

import kglab
kglab.KnowledgeGraph(store="Oxigraph")

NB: note the change in the name of the store, as of Oxrdflib v0.3.0 on 2022-03-19 https://github.com/oxigraph/oxrdflib/releases/tag/v0.3.0

Pros:

  • Speed; we've measured cases of SPARQL queries where Oxrdflib runs ~2 orders of magnitude faster than the default RDFlib.Store implementation.

Cons:

  • Oxrdflib has some troubles with namespaces ... specifically, any prefixes used in a namespace must be explicitly added to each SPARQL query
  • binding variables do not appear to be working
  • result rows from a query differ from the default impl when there are OPTIONAL clauses
  • Oxrdflib uses setup.py to register its RDFlib plugins and it's not clear that this is working properly

We've been able to isolate these issues with a minimum Python code + RDF + SPARQL example, and I'll be opening an issue for Oxrdflib which is linked to this issue.

See also: PRs #240, #241, #242

The SQLAlchemy issues are a different matter. Ostensibly, our new support for specifying a store="foo" in the KnowledgeGraph constructor similarly applies here. The exceptions listed seem to be in the SQLAlchemy store'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.Store plugin in development which is based on NumPy / cuNumeric and it does implement the contexts support.

cc: @paoespinozarias @neobernad @jelisf @Mec-iS

@ceteri
Copy link
Collaborator

ceteri commented Mar 20, 2022

See issue oxigraph/oxrdflib#8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants