GithubHelp home page GithubHelp logo

sparql-anything / pysparql-anything Goto Github PK

View Code? Open in Web Editor NEW
10.0 3.0 0.0 766 KB

The SPARQL Anything Python library

License: Apache License 2.0

Python 100.00%
python sparql linked-data rdf rdflib networkx pandas

pysparql-anything's People

Contributors

enridaga avatar marcor1791 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pysparql-anything's Issues

NetworkX MultiDiGraphs

Currently, the SparqlAnything.construct method returns a rdflib graph object.

While it is not tricky to then convert this to a nx.MultiDiGraph, would it be worth presenting this directly to the user as an option @enridaga ?

exception thrown when running SPARQL Anything

Hi Guys, I have tried to run SPARQL anything onmy laptop and I get the following error. What shall I do?

engine = cli.SparqlAnything()
---------------------------------------------------------------------------
JavaException                             Traceback (most recent call last)
Cell In[3], line 1
----> 1 engine = cli.SparqlAnything()

File ~/anaconda3/envs/py38/lib/python3.8/site-packages/pysparql_anything/sparql_anything.py:20, in SparqlAnything.__init__(self)
     18 def __init__(self):
     19     """ Constructor for the class SparqlAnything."""
---> 20     self.receiver = Engine()

File ~/anaconda3/envs/py38/lib/python3.8/site-packages/pysparql_anything/engine.py:35, in Engine.__init__(self)
     33 """ Constructor for the class Engine. """
     34 location = 'com.github.sparqlanything.cli.SPARQLAnything'
---> 35 self.reflection = autoclass(location)

File ~/anaconda3/envs/py38/lib/python3.8/site-packages/jnius/reflect.py:209, in autoclass(clsname, include_protected, include_private)
    206 cls_start_packagename = '.'.join(clsname.split('.')[:-1])
    208 # c = Class.forName(clsname)
--> 209 c = find_javaclass(clsname)
    210 if c is None:
    211     raise Exception('Java class {0} not found'.format(c))

File jnius/jnius_export_func.pxi:22, in jnius.find_javaclass()

File jnius/jnius_utils.pxi:79, in jnius.check_exception()

JavaException: JVM exception occurred: com/github/sparqlanything/cli/SPARQLAnything java.lang.NoClassDefFoundError

Completed and tested CLI arguments

Python has a more convenient installation method so we should promote it as the primary way of getting the CLI onboard.
However, the Python based CLI does not use the full list of options as the Java version.

More Explicative Keyword Arguments

Rather than the current single letter arguments, q, f, o, etc., it has been suggested by @enridaga that these should be changed to the more explicative query, format, output, etc.

Uninformative error message when query not found

Version: sparql-anything-v0.8.2.jar

This issue is not an important one. It could be a small cosmetic improvement.

When I tried to sa.run() a query as below, it failed because I mistyped the filename, with the error as below. I think the error message could be more informative, eg FileNotFoundError.

In [4]: sa.run(q='query1.sparql')
[main] INFO com.github.sparqlanything.cli.SPARQLAnything - SPARQL anything
---------------------------------------------------------------------------
JavaException                             Traceback (most recent call last)
Cell In[4], line 1
----> 1 sa.run(q='query1.sparql')

File ~\miniconda3\Lib\site-packages\pysparql_anything\sparql_anything.py:30, in SparqlAnything.run(self, **kwargs)
     23 """
     24 The run method replaces the regular command line execution.
     25 @param **kwargs The keyword arguments are the same as the regular
     26     flags for the Sparql Anything CLI, minus the hyphen.
     27 See the User Guide for an example.
     28 """
     29 command = cmd.RunCommand(kwargs, self.receiver)
---> 30 command.execute()

File ~\miniconda3\Lib\site-packages\pysparql_anything\command.py:159, in RunCommand.execute(self)
    157 """ instructions for a run request """
    158 args = super()._combine()
--> 159 self.receiver.main(args)

File ~\miniconda3\Lib\site-packages\pysparql_anything\engine.py:39, in Engine.main(self, args)
     37 def main(self, args):
     38     """ Wrapper for the SPARQL Anything main method. """
---> 39     self.reflection.main(args)

File jnius\\jnius_export_class.pxi:876, in jnius.JavaMethod.__call__()

File jnius\\jnius_export_class.pxi:1059, in jnius.JavaMethod.call_staticmethod()

File jnius\\jnius_utils.pxi:79, in jnius.check_exception()

JavaException: JVM exception occurred: Lexical error at line 1, column 14.  Encountered: <EOF> after prefix "query1.sparql" org.apache.jena.query.QueryParseException

JVM Configuration

The current version does not allow the user to have any control over the JVM and its parameters (e.g. max heap space).

I believe this is mostly due to how pyjnius works, as the JVM is launched at the import statement.
Thus, when pysparql_anything is imported the JVM is launched when __init__.py runs and imports the namespaces.

I believe we need:

  1. Decouple the JVM configuration and launch from the initialisation process and its current location in engine.py.
  2. Create either a specific jvm.py module or create specific function in config.py to make visible to clients (code and users)
    the required functionalities.

Thoughts @enridaga ?

Update Management

As the plan moving forward is to release a new version of PySPARQL Anything for each new SPARQL Anything release, how should we interact with the user with respect to this @enridaga ?

  1. Should we notify the user automatically that a new version is available and then let them proceed manually to the update process, or

  2. Should we notify the user and possibly give them an option (Y/N) to proceed with the update process automatically?

Multiple use of -v flag

The SA user guide states that "the argument can be passed multiple times".

But the Python **kwargs are mapped to a dictionary, which does not allow duplicate keys.

A work around such as say v_i and v_o for input and output variables may be needed for passing arguments to the PySPARQL cli.
These can then be normalised in the implementation before being passed to the SA main method.

@enridaga wdyt?

RDFLib integration

It would be useful if you could directly get an RDFlib Graph object from it. We've been using SA in that way, so we have some code lying around that we could contribute.

pip uninstall issue

As the SA jar is not installed with pip but subsequently, it is also not uninstalled when running pip uninstall.

PySPARQL Anything Entry Point/CLI

The title explains it.

Experimenting with the Python build tools I noticed that we can specify an entry point to the library. This in theory would allow the user to for example be able to call the SparqlAnything.run method directly from the command line without running the Python shell, import statements and create an object.

@enridaga Would you like me to look into this further?

Dependencies

To improve the stability of the release of the module the dependencies need to be better determined in the build proess.

Can't install/import on Windows

PS D:\vc\patterns-knowledge-graph\patterns-knowledge-graph-datasets\RDF> pip install pysparql-anything
Collecting pysparql-anything
  Downloading pysparql_anything-0.8.1.1-py3-none-any.whl (11 kB)
[etc etc]
Successfully installed Deprecated-1.2.14 pygithub-2.1.1 pyjnius-1.6.0 pyjwt-2.8.0 pynacl-1.5.0 pysparql-anything-0.8.1.1 typing-extensions-4.7.1
WARNING: There was an error checking the latest version of pip.
PS D:\vc\patterns-knowledge-graph\patterns-knowledge-graph-datasets\RDF> ipython
In [1]: import pysparql_anything as cli
No SPARQL Anything jar has been found in the installation folder.
Downloading the latest SPARQL Anything jar, please wait...
Downloading SPARQL Anything v0.8.2: 100%|██████████████████████████████████████████████████████████████████████| 198M/198M [00:29<00:00, 7.11MiB/s]
The Download was successful!
The system is now ready for use!
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pysparql_anything\engine.py in <module>
     10     jnius_config.set_classpath(get_path2jar())
---> 11     from jnius import autoclass, JavaException
     12 except ValueError:

~\AppData\Local\Continuum\anaconda3\lib\site-packages\jnius\__init__.py in <module>
     43 else:
---> 44     from .jnius import *  # noqa
     45     from .reflect import *  # noqa

ImportError: DLL load failed: The specified module could not be found.

During handling of the above exception, another exception occurred:

NameError                                 Traceback (most recent call last)
<ipython-input-1-1ac4a47f8b5f> in <module>
----> 1 import pysparql_anything as cli

~\AppData\Local\Continuum\anaconda3\lib\site-packages\pysparql_anything\__init__.py in <module>
     27     raise
     28 # Launches the JVM
---> 29 from pysparql_anything.sparql_anything import SparqlAnything

~\AppData\Local\Continuum\anaconda3\lib\site-packages\pysparql_anything\sparql_anything.py in <module>
      5
      6 import pysparql_anything.command as cmd
----> 7 from pysparql_anything.engine import Engine
      8
      9

~\AppData\Local\Continuum\anaconda3\lib\site-packages\pysparql_anything\engine.py in <module>
     15           + 'create a new VM for the  CLI.')
     16     raise
---> 17 except JavaException:  # Handles JVM exception for an incorrect path
     18     print('JVM exception occured: \n'
     19           + 'Check the jar has been dowloaded succesfully:\n'

NameError: name 'JavaException' is not defined

Inconsistent Docstring Styles and Python Style Guide

The style that I use to write docstrings has changed over time, so that there are multiple styles at once throughout the code at present.

Ideally, the code documentation should be rendered stylistically homogeneous.

On this note, it might be worth settling on a style for the project moving forward, both for the docstrings and the Python code developed.

The official Python documents are 1 and 2 for docstrings and code respectively.

Lately though I have actually been using the Google Python style guide 3, which covers pretty much everything. The only thing I disagree with it is over the linting tool to be used. I find pylint needlessly opinionated in some things and would be inclined more towards flake8 instead.

@enridaga opinions are welcome!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.