From a08cbedc88d971daad2edad3cd279a3945ac2235 Mon Sep 17 00:00:00 2001 From: Hoda Date: Mon, 13 Nov 2023 22:35:33 +0100 Subject: [PATCH 1/4] Add command-line argument for passing LPG2RDFConfiguration description --- .../liu/ida/hefquin/cli/RunBGPOverNeo4j.java | 26 +++----------- .../cli/modules/ModLPG2RDFConfiguration.java | 34 +++++++++++++++++++ 2 files changed, 38 insertions(+), 22 deletions(-) create mode 100644 src/main/java/se/liu/ida/hefquin/cli/modules/ModLPG2RDFConfiguration.java diff --git a/src/main/java/se/liu/ida/hefquin/cli/RunBGPOverNeo4j.java b/src/main/java/se/liu/ida/hefquin/cli/RunBGPOverNeo4j.java index bf1b1d8d7..22b22276f 100644 --- a/src/main/java/se/liu/ida/hefquin/cli/RunBGPOverNeo4j.java +++ b/src/main/java/se/liu/ida/hefquin/cli/RunBGPOverNeo4j.java @@ -7,7 +7,6 @@ import arq.cmdline.ModTime; import org.apache.jena.cmd.ArgDecl; -import org.apache.jena.graph.NodeFactory; import org.apache.jena.query.Query; import org.apache.jena.query.ResultSet; import org.apache.jena.sparql.core.Var; @@ -16,6 +15,7 @@ import org.apache.jena.sparql.syntax.ElementPathBlock; import org.apache.jena.sparql.util.QueryExecUtils; +import se.liu.ida.hefquin.cli.modules.ModLPG2RDFConfiguration; import se.liu.ida.hefquin.cli.modules.ModQuery; import se.liu.ida.hefquin.engine.data.SolutionMapping; import se.liu.ida.hefquin.engine.data.VocabularyMapping; @@ -34,17 +34,8 @@ import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.LPG2RDFConfiguration; import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.Record2SolutionMappingTranslator; import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.SPARQLStar2CypherTranslator; -import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.LPG2RDFConfigurationImpl; import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.Record2SolutionMappingTranslatorImpl; import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.SPARQLStar2CypherTranslatorImpl; -import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.NodeMapping; -import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.NodeMappingToURIsImpl; -import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.NodeLabelMapping; -import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.NodeLabelMappingToURIsImpl; -import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.EdgeLabelMapping; -import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.EdgeLabelMappingToURIsImpl; -import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.PropertyNameMapping; -import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.PropertyNameMappingToURIsImpl; import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.query.CypherMatchQuery; import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.query.CypherQuery; import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.query.CypherUnionQuery; @@ -58,6 +49,7 @@ public class RunBGPOverNeo4j extends CmdARQ protected final ModTime modTime = new ModTime(); protected final ModQuery modQuery = new ModQuery(); protected final ModResultsOut modResults = new ModResultsOut(); + protected final ModLPG2RDFConfiguration modLPG2RDFConfiguration = new ModLPG2RDFConfiguration(); protected final ArgDecl argEndpointURI = new ArgDecl(ArgDecl.HasValue, "endpoint"); protected final ArgDecl argNaive = new ArgDecl(ArgDecl.NoValue, "naive"); @@ -65,13 +57,6 @@ public class RunBGPOverNeo4j extends CmdARQ protected final ArgDecl argNoMerge = new ArgDecl(ArgDecl.NoValue, "disablePathMerging"); protected final ArgDecl argSuppressResultPrintout = new ArgDecl(ArgDecl.NoValue, "suppressResultPrintout"); - protected static final String LABEL = "http://www.w3.org/2000/01/rdf-schema#label"; - - protected static final String NSNODE = "https://example.org/node/"; - protected static final String NSNODELABEL = "https://example.org/label/"; - protected static final String NSRELATIONSHIP = "https://example.org/relationship/"; - protected static final String NSPROPERTY = "https://example.org/property/"; - public static void main( final String[] args ) { new RunBGPOverNeo4j(args).mainRun(); } @@ -85,6 +70,7 @@ protected RunBGPOverNeo4j( final String[] argv ) { add(argSuppressResultPrintout, "--suppressResultPrintout", "Do not print out the query result"); addModule(modQuery); + addModule(modLPG2RDFConfiguration); add(argEndpointURI, "--endpoint", "The URI of the Neo4j endpoint"); add(argNaive, "--naive", "If you want naive translation"); @@ -102,11 +88,7 @@ protected String getSummary() { protected void exec() { final BGP bgp = getBGP(); - final NodeMapping nodeMapping = new NodeMappingToURIsImpl(NSNODE); - final NodeLabelMapping nodeLabelMapping = new NodeLabelMappingToURIsImpl(NSNODELABEL); - final EdgeLabelMapping edgeLabelMapping = new EdgeLabelMappingToURIsImpl(NSRELATIONSHIP); - final PropertyNameMapping propertyNameMapping = new PropertyNameMappingToURIsImpl(NSPROPERTY); - final LPG2RDFConfiguration conf = new LPG2RDFConfigurationImpl(NodeFactory.createURI(LABEL), nodeMapping, nodeLabelMapping,edgeLabelMapping,propertyNameMapping); + final LPG2RDFConfiguration conf = modLPG2RDFConfiguration.getLPG2RDFConfigurationCatalog(); final Pair> tRes = performQueryTranslation(bgp, conf); diff --git a/src/main/java/se/liu/ida/hefquin/cli/modules/ModLPG2RDFConfiguration.java b/src/main/java/se/liu/ida/hefquin/cli/modules/ModLPG2RDFConfiguration.java new file mode 100644 index 000000000..e535a92c9 --- /dev/null +++ b/src/main/java/se/liu/ida/hefquin/cli/modules/ModLPG2RDFConfiguration.java @@ -0,0 +1,34 @@ +package se.liu.ida.hefquin.cli.modules; + +import org.apache.jena.cmd.ArgDecl; +import org.apache.jena.cmd.CmdArgModule; +import org.apache.jena.cmd.CmdGeneral; +import org.apache.jena.cmd.ModBase; +import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.LPG2RDFConfiguration; +import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.LPG2RDFConfigurationReader; + +public class ModLPG2RDFConfiguration extends ModBase { + protected final ArgDecl lpg2RDFDescrDecl = new ArgDecl(ArgDecl.HasValue, "LPG2RDFConfigurationDescription", "lpg2rdf"); + + protected LPG2RDFConfiguration cat = null; + + @Override + public void registerWith( final CmdGeneral cmdLine ) { + cmdLine.getUsage().startCategory("LPG2RDFConfigurationDescription"); + cmdLine.add(lpg2RDFDescrDecl, "--LPG2RDFConfigurationDescription", "file with an RDF description of the LPG2RDFConfiguration"); + } + + @Override + public void processArgs( final CmdArgModule cmdLine ) { + if ( cmdLine.contains(lpg2RDFDescrDecl) ) { + final String lpg2RDFDescrFilename = cmdLine.getValue(lpg2RDFDescrDecl); + cat = LPG2RDFConfigurationReader.readFromFile(lpg2RDFDescrFilename); + } + } + + + public LPG2RDFConfiguration getLPG2RDFConfigurationCatalog() { + return cat; + } + +} From 8b86f9233f526d0196d0a408e8c5ed5676f5db59 Mon Sep 17 00:00:00 2001 From: Hoda Date: Tue, 14 Nov 2023 18:54:15 +0100 Subject: [PATCH 2/4] Improve command-line argument of LPG2RDFConfiguration description --- .../liu/ida/hefquin/cli/RunBGPOverNeo4j.java | 2 +- .../cli/modules/ModLPG2RDFConfiguration.java | 29 +++++++++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/main/java/se/liu/ida/hefquin/cli/RunBGPOverNeo4j.java b/src/main/java/se/liu/ida/hefquin/cli/RunBGPOverNeo4j.java index 22b22276f..27a72767f 100644 --- a/src/main/java/se/liu/ida/hefquin/cli/RunBGPOverNeo4j.java +++ b/src/main/java/se/liu/ida/hefquin/cli/RunBGPOverNeo4j.java @@ -69,8 +69,8 @@ protected RunBGPOverNeo4j( final String[] argv ) { add(argSuppressResultPrintout, "--suppressResultPrintout", "Do not print out the query result"); - addModule(modQuery); addModule(modLPG2RDFConfiguration); + addModule(modQuery); add(argEndpointURI, "--endpoint", "The URI of the Neo4j endpoint"); add(argNaive, "--naive", "If you want naive translation"); diff --git a/src/main/java/se/liu/ida/hefquin/cli/modules/ModLPG2RDFConfiguration.java b/src/main/java/se/liu/ida/hefquin/cli/modules/ModLPG2RDFConfiguration.java index e535a92c9..30474a605 100644 --- a/src/main/java/se/liu/ida/hefquin/cli/modules/ModLPG2RDFConfiguration.java +++ b/src/main/java/se/liu/ida/hefquin/cli/modules/ModLPG2RDFConfiguration.java @@ -4,18 +4,34 @@ import org.apache.jena.cmd.CmdArgModule; import org.apache.jena.cmd.CmdGeneral; import org.apache.jena.cmd.ModBase; +import org.apache.jena.graph.NodeFactory; import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.LPG2RDFConfiguration; +import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.NodeMapping; +import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.NodeMappingToURIsImpl; +import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.NodeLabelMapping; +import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.NodeLabelMappingToURIsImpl; +import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.EdgeLabelMapping; +import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.EdgeLabelMappingToURIsImpl; +import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.PropertyNameMapping; +import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.PropertyNameMappingToURIsImpl; +import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.LPG2RDFConfigurationImpl; import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.LPG2RDFConfigurationReader; public class ModLPG2RDFConfiguration extends ModBase { - protected final ArgDecl lpg2RDFDescrDecl = new ArgDecl(ArgDecl.HasValue, "LPG2RDFConfigurationDescription", "lpg2rdf"); + protected final ArgDecl lpg2RDFDescrDecl = new ArgDecl(ArgDecl.HasValue, "lpg2rdfconf", "lpg2rdf", "LPG2RDFConfigurationDescription"); + protected static final String NSNODE = "https://example.org/node/"; + protected static final String NSNODELABEL = "https://example.org/label/"; + protected static final String NSRELATIONSHIP = "https://example.org/relationship/"; + protected static final String NSPROPERTY = "https://example.org/property/"; + protected static final String LABEL = "http://www.w3.org/2000/01/rdf-schema#label"; + protected LPG2RDFConfiguration cat = null; @Override public void registerWith( final CmdGeneral cmdLine ) { - cmdLine.getUsage().startCategory("LPG2RDFConfigurationDescription"); - cmdLine.add(lpg2RDFDescrDecl, "--LPG2RDFConfigurationDescription", "file with an RDF description of the LPG2RDFConfiguration"); + cmdLine.getUsage().startCategory("LPG to RDF Mapping"); + cmdLine.add(lpg2RDFDescrDecl, "--lpg2rdfconf", "file with an RDF description of the LPG-to-RDF configuration"); } @Override @@ -24,6 +40,13 @@ public void processArgs( final CmdArgModule cmdLine ) { final String lpg2RDFDescrFilename = cmdLine.getValue(lpg2RDFDescrDecl); cat = LPG2RDFConfigurationReader.readFromFile(lpg2RDFDescrFilename); } + else{ + final NodeMapping nodeMapping = new NodeMappingToURIsImpl(NSNODE); + final NodeLabelMapping nodeLabelMapping = new NodeLabelMappingToURIsImpl(NSNODELABEL); + final EdgeLabelMapping edgeLabelMapping = new EdgeLabelMappingToURIsImpl(NSRELATIONSHIP); + final PropertyNameMapping propertyNameMapping = new PropertyNameMappingToURIsImpl(NSPROPERTY); + cat = new LPG2RDFConfigurationImpl(NodeFactory.createURI(LABEL), nodeMapping, nodeLabelMapping,edgeLabelMapping,propertyNameMapping); + } } From 51877bd01ab5c7d3dee16a5d07579e71a53d742c Mon Sep 17 00:00:00 2001 From: Hoda Date: Tue, 14 Nov 2023 20:37:19 +0100 Subject: [PATCH 3/4] Change default NodeLabelMapping from IRI-Based to Literal-Based NodeLabelMapping --- .../cli/modules/ModLPG2RDFConfiguration.java | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/main/java/se/liu/ida/hefquin/cli/modules/ModLPG2RDFConfiguration.java b/src/main/java/se/liu/ida/hefquin/cli/modules/ModLPG2RDFConfiguration.java index 30474a605..16f169a78 100644 --- a/src/main/java/se/liu/ida/hefquin/cli/modules/ModLPG2RDFConfiguration.java +++ b/src/main/java/se/liu/ida/hefquin/cli/modules/ModLPG2RDFConfiguration.java @@ -6,16 +6,7 @@ import org.apache.jena.cmd.ModBase; import org.apache.jena.graph.NodeFactory; import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.LPG2RDFConfiguration; -import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.NodeMapping; -import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.NodeMappingToURIsImpl; -import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.NodeLabelMapping; -import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.NodeLabelMappingToURIsImpl; -import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.EdgeLabelMapping; -import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.EdgeLabelMappingToURIsImpl; -import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.PropertyNameMapping; -import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.PropertyNameMappingToURIsImpl; -import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.LPG2RDFConfigurationImpl; -import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.LPG2RDFConfigurationReader; +import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.*; public class ModLPG2RDFConfiguration extends ModBase { protected final ArgDecl lpg2RDFDescrDecl = new ArgDecl(ArgDecl.HasValue, "lpg2rdfconf", "lpg2rdf", "LPG2RDFConfigurationDescription"); @@ -42,7 +33,7 @@ public void processArgs( final CmdArgModule cmdLine ) { } else{ final NodeMapping nodeMapping = new NodeMappingToURIsImpl(NSNODE); - final NodeLabelMapping nodeLabelMapping = new NodeLabelMappingToURIsImpl(NSNODELABEL); + final NodeLabelMapping nodeLabelMapping = new NodeLabelMappingToLiteralsImpl(); final EdgeLabelMapping edgeLabelMapping = new EdgeLabelMappingToURIsImpl(NSRELATIONSHIP); final PropertyNameMapping propertyNameMapping = new PropertyNameMappingToURIsImpl(NSPROPERTY); cat = new LPG2RDFConfigurationImpl(NodeFactory.createURI(LABEL), nodeMapping, nodeLabelMapping,edgeLabelMapping,propertyNameMapping); From 5cb6db0072a9e5fbe3ec15ca320716ed38733cfc Mon Sep 17 00:00:00 2001 From: Olaf Hartig Date: Tue, 14 Nov 2023 21:18:24 +0100 Subject: [PATCH 4/4] Line not needed anymore --- .../se/liu/ida/hefquin/cli/modules/ModLPG2RDFConfiguration.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/se/liu/ida/hefquin/cli/modules/ModLPG2RDFConfiguration.java b/src/main/java/se/liu/ida/hefquin/cli/modules/ModLPG2RDFConfiguration.java index 16f169a78..368954725 100644 --- a/src/main/java/se/liu/ida/hefquin/cli/modules/ModLPG2RDFConfiguration.java +++ b/src/main/java/se/liu/ida/hefquin/cli/modules/ModLPG2RDFConfiguration.java @@ -11,7 +11,6 @@ public class ModLPG2RDFConfiguration extends ModBase { protected final ArgDecl lpg2RDFDescrDecl = new ArgDecl(ArgDecl.HasValue, "lpg2rdfconf", "lpg2rdf", "LPG2RDFConfigurationDescription"); protected static final String NSNODE = "https://example.org/node/"; - protected static final String NSNODELABEL = "https://example.org/label/"; protected static final String NSRELATIONSHIP = "https://example.org/relationship/"; protected static final String NSPROPERTY = "https://example.org/property/"; protected static final String LABEL = "http://www.w3.org/2000/01/rdf-schema#label";