XML Sparql results from rdflib - rdflib

I am using Graph() in RDFLib, i am correctly getting results of from the graph using sparql. Is it possible to get the results directly in HTML table format?

rdflib is a library to work with rdf in python, not an HTML rendering engine. Usually if you work on a graph.sparql() query, you want to access the result in python itself.
That said, there is a fork focusing on hosting RDF called rdflib-web. In it you can find a htmlresults.py which does pretty much what i think you want.

Related

Using saxon & XPath 3.1 to parse JSON files

This is for the case of calling Saxon from a Java application. I understand that Saxon can use XPath 3.1 to run queries against JSON files. A couple of question on this:
Where is there an example of how to do this? I've done searches and find lots of answers on details of doing this, but noting on how to read in the file and perform queries. Is it the same as XML?
Is it possible to have a schema file for the JSON so returned values are correctly typed? If so, how?
Is XQuery also able to perform queries on JSON?
What version of Saxon supports this? (We are using 9.9.1.1 and want to know if I need to upgrade.)
Technically, you don't run queries against JSON files; you run them against the data structure that results from parsing a JSON file, which is a structure of maps and arrays. You can parse the JSON file using the parse-json() or json-doc() functions, and then query the result using operators that work on maps and arrays. Some of these (and examples of their use) are shown in the spec at
https://www.w3.org/TR/xpath-31/#id-maps-and-arrays
Googling for "query maps arrays JSON XPath 3.1" finds quite a lot of useful material. Or get Priscilla Walmsley's book: http://www.datypic.com/books/xquery/chapter24.html
Data types: the data types of string, number, and boolean that are intrinsic to JSON are automatically recognized by their form. There's no capability to do further typing using a schema.
XQuery is a superset of XPath, but as far as JSON/Maps/Arrays are concerned, I think the facilities in XPath and those in XQuery are exactly the same.
Saxon has added a bit of extra conformance and performance in each successive release. 9.9 is pretty complete in its coverage; 10.0 adds some optimizations (like a new internal data structure for maps whose keys are all strings, such as you get when you parse JSON). Details of changes in successive Saxon releases are described in copious detail at http://www.saxonica.com/documentation/index.html#!changes

What are the advantages and disadvantages of using from_xml function in ruby

I want to use the from_xml method provided by the rails active support core ext,
An example :
hash = Hash.from_xml("my_xml.xml")
for converting XML into a Hash.
I want to use this because parsing a Hash is a lot easier than XML in ruby.
However, I would want to know what are the pros and cons of using this approach. Is there a better approach I can use for converting an XML into hash.
Thanks
XML unlike JSON is a document format and not just data exchange format and not always actually maps cleanly to programming language constructs like hashes. XML is actually ridiculously complex if you look at all the features like namespaces.
Hash.from_xml really only handles the simplest of cases and doesn't have a clue how to deal with stuff like attributes. It really only knows how to parse the XML generated by Hash#to_xml.
Advantages:
its so naive that its cute
Disadvantages:
see advantages
For non-trivial examples you'll need an actual XML parser like Nokogiri.

ArangoDB - how to import neo4j database export into ArangoDB

Are there any utilities to import database from Neo4j into ArangoDB? arangoimp utility expects the data to be in certain format for edges and vertices than what is exported by Neo4j.
Thanks!
Note: This is not an answer per se, but a comment wouldn't allow me to structure the information I gathered in a readable way.
Resources online seem to be scarce w/r to the transition from neo4j to arangodb.
One possible way is to combine APOC (https://github.com/neo4j-contrib/neo4j-apoc-procedures) and neo4j-shell-tools (https://github.com/jexp/neo4j-shell-tools)
Use apoc to create a cypher export file for the database (see https://neo4j.com/developer/kb/export-sub-graph-to-cypher-and-import/)
Use the neo4j-shell-tool cypher import with the -o switch -- this should generate csv-files
Analyse the csv-files,
massage them with csvtool OR
create json-data with one of the numerous csv2json converters available (npm, ...) and massage these files with jq
Feed the files to arangoimp, repeat 3 if necessary
There is also a graphml to json converter (https://github.com/uskudnik/GraphGL/blob/master/examples/graphml-to-json.py) available, so that you could use the afforementioned neo4j-shell-tools to export to graphml, convert this representation to json and massage these files to the necessary format.
I'm sorry that I can't be of more help, but maybe these thoughts get you started.

Can we check the translated function calls generated by Cypher or Gremlin?

I believe internally Cypher / Gremlin translate statement into corresponding Java method calls. Is there a way to trace what method calls in run?
For example, in Hibernate, we can specify "show sql" to see generated sql statement.
[Edit]
The reasonws I want to do that:
1. For Debugging purpose:
To find out why the cypher / gremlin doesn't produce the expected result.
For learning purpose:
To find what's happening under the hood
For optimization:
To find out where the bottleneck is.
In Cypher, that is planned for the coming months to add. Ultimately, yes, currently the methods used under the Hood are the Java Neo4j core API and the Traversal Framework. Mind adding a case that is causing you problem?
For Gremlin, do a .toString() at the end of your Gremlin expression to see which Pipes (http://pipes.tinkerpop.com) it ultimately compiles down to.

Convert Neo4j DB to XML?

Can I convert Neo4J Database files to XML?
I agree, GraphML is the way to go, if you don't have problems with the verbosity of XML. A simple way to do it is to open the Neo4j graph from Gremlin, where GraphML is the default import/export format, something like
peters: ./gremlin.sh
gremlin> $_g := neo4j:open('/tmp/neo4j')
==>neograph[/tmp/neo4j, vertices:2, edges:1]
gremlin> g:save('graphml-export.xml')
As described here
Does that solve your problem?
With Blueprints, simply do:
Graph graph = new Neo4jGraph("/tmp/mygraph");
GraphMLWriter.outputGraph(graph, new FileOutputStream("mygraph.xml"));
Or, with Gremlin (which does the same thing in the back):
g = new Neo4jGraph('/tmp/mygraph');
g.saveGraphML('mygraph.xml');
Finally, to the constructor for Neo4jGraph, you can also pass in a GraphDatabaseService instance.
I don't believe anything exists out there for this, not as of few months ago when messing with it. From what I saw, there are 2 main roadblocks:
XML is hierarchical, you can't represent graph data readily in this format.
Lack of explicit IDs for nodes. Even though implicit IDs exist it'd be like using ROWID in oracle for import/export...not guaranteed to be the same.
Some people have suggested that GraphML would be the proper format for this, I'm inclined to agree. If you don't have graphical structures and you would be fine represented in an XML/hierarchical format...well then that's just bad luck. Since the majority of users who would tackle this sort of enhancement task are using data that wouldn't store that way, I don't see an XML solution coming out...more likely to see a format supporting all uses first.
Take a look at NoSqlUnit
It has tools for converting GraphML to neo4j and back again.
In particular, there is com.lordofthejars.nosqlunit.graph.parser.GraphMLWriter and com.lordofthejars.nosqlunit.graph.parser.GraphMLReader which read / write XML files to / from a neo4j database.

Resources