Skip to content

Integration with rdflib-sqlalchemy, oxrdflib #203

Open

Description

@davidshumway

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'

Activity

  1. added
    help wantedExtra attention is needed
    questionFurther information is requested
    on Mar 19, 2022
  2. self-assigned this
    on Mar 19, 2022
  3. ceteri commented on Mar 19, 2022

    @ceteri
    Collaborator

    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

  4. ceteri commented on Mar 20, 2022

    @ceteri
    Collaborator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

help wantedExtra attention is neededquestionFurther information is requested

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions