Mentions légales du service

Skip to content
Snippets Groups Projects
Commit c701e931 authored by Jérôme Euzenat's avatar Jérôme Euzenat
Browse files

- Made TransformQuery accepting standard input as well as parameter

parent 78aaf5e8
No related branches found
No related tags found
No related merge requests found
...@@ -48,10 +48,11 @@ import org.semanticweb.owl.align.AlignmentException; ...@@ -48,10 +48,11 @@ import org.semanticweb.owl.align.AlignmentException;
/** /**
* Transform a query according to an alignment * Transform a query according to an alignment
* TransformQuery alignmentURI -q query [-e]
* would be better with:
* TransformQuery [-a alignmentURI] [-e] [-q query] < query * TransformQuery [-a alignmentURI] [-e] [-q query] < query
* definitely...todo * Query can be taken from (priority):
* - parameter
* - a queryfile (-q)
* - standard input
*/ */
public class TransformQuery extends CommonCLI { public class TransformQuery extends CommonCLI {
...@@ -62,6 +63,7 @@ public class TransformQuery extends CommonCLI { ...@@ -62,6 +63,7 @@ public class TransformQuery extends CommonCLI {
options.addOption( "e", "echo", false, "Echo the input query" ); options.addOption( "e", "echo", false, "Echo the input query" );
//options.addOption( OptionBuilder.withLongOpt( "process" ).hasArg().withDescription( "Process the query against a particular CLASS" ).withArgName("CLASS").create( 'p' ) ); //options.addOption( OptionBuilder.withLongOpt( "process" ).hasArg().withDescription( "Process the query against a particular CLASS" ).withArgName("CLASS").create( 'p' ) );
options.addOption( OptionBuilder.withLongOpt( "query" ).hasArg().withDescription( "get the query from the corresponding FILE" ).withArgName("FILE").create( 'q' ) ); options.addOption( OptionBuilder.withLongOpt( "query" ).hasArg().withDescription( "get the query from the corresponding FILE" ).withArgName("FILE").create( 'q' ) );
options.addOption( OptionBuilder.withLongOpt( "alignment" ).hasArg().withDescription( "use the alignment identified by URI" ).withArgName("URI").create( 'a' ) );
} }
public static void main(String[] args) { public static void main(String[] args) {
...@@ -72,7 +74,7 @@ public class TransformQuery extends CommonCLI { ...@@ -72,7 +74,7 @@ public class TransformQuery extends CommonCLI {
public void run(String[] args) throws Exception { public void run(String[] args) throws Exception {
BasicAlignment al = null; BasicAlignment al = null;
String alignmentURL = null; String alignmentURL = null;
String query = ""; String query = null;
String result = null; String result = null;
//String processorClass = null; //String processorClass = null;
String queryFile = null; String queryFile = null;
...@@ -86,14 +88,11 @@ public class TransformQuery extends CommonCLI { ...@@ -86,14 +88,11 @@ public class TransformQuery extends CommonCLI {
// Here deal with command specific arguments // Here deal with command specific arguments
//if ( line.hasOption( 'p' ) ) processorClass = line.getOptionValue( 'p' ); //if ( line.hasOption( 'p' ) ) processorClass = line.getOptionValue( 'p' );
if ( line.hasOption( 'q' ) ) queryFile = line.getOptionValue( 'q' ); if ( line.hasOption( 'q' ) ) queryFile = line.getOptionValue( 'q' );
if ( line.hasOption( 'a' ) ) alignmentURL = line.getOptionValue( 'a' );
if ( line.hasOption( 'e' ) ) echo = true; if ( line.hasOption( 'e' ) ) echo = true;
String[] argList = line.getArgs(); String[] argList = line.getArgs();
if ( argList.length > 0 ) { if ( argList.length > 0 ) {
alignmentURL = argList[0]; query = argList[0];
} else {
logger.error("Require the alignement URL");
usage();
System.exit(-1);
} }
} catch( ParseException exp ) { } catch( ParseException exp ) {
logger.error( exp.getMessage() ); logger.error( exp.getMessage() );
...@@ -102,29 +101,34 @@ public class TransformQuery extends CommonCLI { ...@@ -102,29 +101,34 @@ public class TransformQuery extends CommonCLI {
} }
try { try {
if ( query == null ) {
try { query = "";
InputStream in = new FileInputStream( queryFile ); try {
BufferedReader reader = InputStream in = (queryFile!=null)?new FileInputStream( queryFile ):System.in;
new BufferedReader(new InputStreamReader(in)); BufferedReader reader = new BufferedReader( new InputStreamReader(in) );
String line = null; String line = null;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
query += line + "\n"; query += line + "\n";
}
} catch (IOException x) {
System.err.println(x);
System.exit( -1 );
//} finally {
} }
} catch (IOException x) {
System.err.println(x);
System.exit( -1 );
//} finally {
} }
// load the alignment
AlignmentParser aparser = new AlignmentParser();
al = (BasicAlignment)aparser.parse( alignmentURL );
if ( echo ) System.out.println( query ); if ( echo ) System.out.println( query );
// Create query processor // load the alignment
result = al.rewriteQuery( query, parameters ); if ( alignmentURL != null ) {
AlignmentParser aparser = new AlignmentParser();
al = (BasicAlignment)aparser.parse( alignmentURL );
// Create query processor
result = al.rewriteQuery( query, parameters );
} else {
result = query;
}
// Set output file // Set output file
OutputStream stream; OutputStream stream;
...@@ -143,9 +147,8 @@ public class TransformQuery extends CommonCLI { ...@@ -143,9 +147,8 @@ public class TransformQuery extends CommonCLI {
} finally { } finally {
writer.flush(); writer.flush();
writer.close(); writer.close();
} }}
catch (Exception ex) {
} catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
logger.error( ex.getMessage() ); logger.error( ex.getMessage() );
System.exit(-1); System.exit(-1);
...@@ -153,6 +156,6 @@ public class TransformQuery extends CommonCLI { ...@@ -153,6 +156,6 @@ public class TransformQuery extends CommonCLI {
} }
public void usage() { public void usage() {
usage( "java "+this.getClass().getName()+" [options] alignmentURI query\nTransforms the given query and transforms it according to the alignment" ); usage( "java "+this.getClass().getName()+" [options] QUERY\nTransforms the given QUERY according to an alignment" );
} }
} }
...@@ -19,8 +19,6 @@ mkdir -p $RESDIR ...@@ -19,8 +19,6 @@ mkdir -p $RESDIR
# GOTO # GOTO
if false; then if false; then
echo this is for avoiding some parts echo this is for avoiding some parts
#GOTO
fi
echo "\t\tTHE -z OPTIONS RELY ON LOGBACK BEING PROPERLY DEFINED" echo "\t\tTHE -z OPTIONS RELY ON LOGBACK BEING PROPERLY DEFINED"
echo "\t\t *** Testing Procalign ***" echo "\t\t *** Testing Procalign ***"
...@@ -939,6 +937,9 @@ echo "\t(same as Procalign)" ...@@ -939,6 +937,9 @@ echo "\t(same as Procalign)"
echo "\t-P,--params <FILE>" echo "\t-P,--params <FILE>"
echo "\t(same as Procalign)" echo "\t(same as Procalign)"
#GOTO
fi
######################################################################## ########################################################################
# TransformQuery # TransformQuery
######################################################################## ########################################################################
...@@ -962,9 +963,39 @@ java -cp $CP fr.inrialpes.exmo.align.cli.TransformQuery --help &> $RESDIR/queryt ...@@ -962,9 +963,39 @@ java -cp $CP fr.inrialpes.exmo.align.cli.TransformQuery --help &> $RESDIR/queryt
if [ -s $RESDIR/queryt-h.txt ]; then diff $RESDIR/queryt-h.txt $RESDIR/queryt-help.txt; else echo error with $RESDIR/queryt-h.txt; fi if [ -s $RESDIR/queryt-h.txt ]; then diff $RESDIR/queryt-h.txt $RESDIR/queryt-help.txt; else echo error with $RESDIR/queryt-h.txt; fi
#------------------- #-------------------
echo "\tno-op" echo "\tno-op (not testable because wait for input)"
java -cp $CP fr.inrialpes.exmo.align.cli.TransformQuery &> $RESDIR/queryt-noop.rdf #java -cp $CP fr.inrialpes.exmo.align.cli.TransformQuery &> $RESDIR/queryt-noop.rdf
if [ -s $RESDIR/queryt-noop.xml ]; then echo error with TRANSQ-NOOP; fi #if [ ! -s $RESDIR/queryt-noop.xml ]; then echo error with TRANSQ-NOOP; fi
#-------------------
echo "\t<QUERY>"
java -cp $CP fr.inrialpes.exmo.align.cli.TransformQuery 'PREFIX dt: <http://example.org/datatype#> .
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
PREFIX xmls: <http://www.w3.org/2001/XMLSchema#> .
PREFIX foaf: <http://xmlns.com/foaf/0.1/> .
PREFIX onto1: <http://www.example.org/ontology1#> .
SELECT *
FROM XXX
WHERE {
?X rdf:type <http://www.example.org/ontology1#reviewedarticle>.
?X rdf:type onto1:reviewedarticle .
}' > $RESDIR/queryt-q0.rdf
diff $RESDIR/queryt-q0.rdf $CWD/examples/rdf/query.sparql
java -cp $CP fr.inrialpes.exmo.align.cli.TransformQuery -a file://$CWD/examples/rdf/newsample.rdf 'PREFIX dt: <http://example.org/datatype#> .
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
PREFIX xmls: <http://www.w3.org/2001/XMLSchema#> .
PREFIX foaf: <http://xmlns.com/foaf/0.1/> .
PREFIX onto1: <http://www.example.org/ontology1#> .
SELECT *
FROM XXX
WHERE {
?X rdf:type <http://www.example.org/ontology1#reviewedarticle>.
?X rdf:type onto1:reviewedarticle .
}' > $RESDIR/queryt-q1.rdf
if [ -s $RESDIR/queryt-q1.rdf ]; then diff $RESDIR/queryt-q1.rdf $RESDIR/queryt-noop.rdf > $RESDIR/diff-query1.txt; else echo error with TRANSQ-QUERY1; fi
if [ ! -s $RESDIR/diff-query1.txt ]; then echo error with TRANSQ-QUERY2; fi
#------------------- #-------------------
echo "\t-q,--query <FILE>" echo "\t-q,--query <FILE>"
...@@ -974,26 +1005,34 @@ if [ ! -s $RESDIR/diff-query1.txt ]; then echo error with TRANSQ-QUERY2; fi ...@@ -974,26 +1005,34 @@ if [ ! -s $RESDIR/diff-query1.txt ]; then echo error with TRANSQ-QUERY2; fi
java -cp $CP fr.inrialpes.exmo.align.cli.TransformQuery file://$CWD/examples/rdf/newsample.rdf --query $CWD/examples/rdf/query.sparql > $RESDIR/queryt-q2.rdf java -cp $CP fr.inrialpes.exmo.align.cli.TransformQuery file://$CWD/examples/rdf/newsample.rdf --query $CWD/examples/rdf/query.sparql > $RESDIR/queryt-q2.rdf
diff $RESDIR/queryt-q1.rdf $RESDIR/queryt-q2.rdf diff $RESDIR/queryt-q1.rdf $RESDIR/queryt-q2.rdf
#-------------------
echo "\t-a,--alignment <URI>"
java -cp $CP fr.inrialpes.exmo.align.cli.TransformQuery -a file://$CWD/examples/rdf/newsample.rdf -q $CWD/examples/rdf/query.sparql > $RESDIR/queryt-q1.rdf
if [ -s $RESDIR/queryt-q1.rdf ]; then diff $RESDIR/queryt-q1.rdf $RESDIR/queryt-noop.rdf > $RESDIR/diff-query1.txt; else echo error with TRANSQ-QUERY1; fi
if [ ! -s $RESDIR/diff-query1.txt ]; then echo error with TRANSQ-QUERY2; fi
java -cp $CP fr.inrialpes.exmo.align.cli.TransformQuery --alignment file://$CWD/examples/rdf/newsample.rdf --query $CWD/examples/rdf/query.sparql > $RESDIR/queryt-q2.rdf
diff $RESDIR/queryt-q1.rdf $RESDIR/queryt-q2.rdf
#------------------- #-------------------
echo "\t-o <F>, --output <F>" echo "\t-o <F>, --output <F>"
java -cp $CP fr.inrialpes.exmo.align.cli.TransformQuery file://$CWD/examples/rdf/newsample.rdf -q $CWD/examples/rdf/query.sparql -o $RESDIR/queryt-o1.rdf java -cp $CP fr.inrialpes.exmo.align.cli.TransformQuery -a file://$CWD/examples/rdf/newsample.rdf -q $CWD/examples/rdf/query.sparql -o $RESDIR/queryt-o1.rdf
if [ -s $RESDIR/queryt-o1.rdf ]; then diff $RESDIR/queryt-o1.rdf $RESDIR/queryt-noop.rdf > $RESDIR/diff-output1.txt; else echo error with TRANSQ-OUTPUT1; fi if [ -s $RESDIR/queryt-o1.rdf ]; then diff $RESDIR/queryt-o1.rdf $RESDIR/queryt-noop.rdf > $RESDIR/diff-output1.txt; else echo error with TRANSQ-OUTPUT1; fi
if [ ! -s $RESDIR/diff-output1.txt ]; then echo error with TRANSQ-OUTPUT2; fi if [ ! -s $RESDIR/diff-output1.txt ]; then echo error with TRANSQ-OUTPUT2; fi
diff $RESDIR/queryt-o1.rdf $RESDIR/queryt-q1.rdf diff $RESDIR/queryt-o1.rdf $RESDIR/queryt-q1.rdf
java -cp $CP fr.inrialpes.exmo.align.cli.TransformQuery file://$CWD/examples/rdf/newsample.rdf --query $CWD/examples/rdf/query.sparql --output $RESDIR/queryt-o2.rdf java -cp $CP fr.inrialpes.exmo.align.cli.TransformQuery --alignment file://$CWD/examples/rdf/newsample.rdf --query $CWD/examples/rdf/query.sparql --output $RESDIR/queryt-o2.rdf
diff $RESDIR/queryt-o1.rdf $RESDIR/queryt-o2.rdf diff $RESDIR/queryt-o1.rdf $RESDIR/queryt-o2.rdf
#------------------- #-------------------
echo "\t-e,--echo" echo "\t-e,--echo"
java -cp $CP fr.inrialpes.exmo.align.cli.TransformQuery file://$CWD/examples/rdf/newsample.rdf -q $CWD/examples/rdf/query.sparql -e > $RESDIR/queryt-e1.rdf java -cp $CP fr.inrialpes.exmo.align.cli.TransformQuery -a file://$CWD/examples/rdf/newsample.rdf -q $CWD/examples/rdf/query.sparql -e > $RESDIR/queryt-e1.rdf
if [ -s $RESDIR/queryt-e1.rdf ]; then diff $RESDIR/queryt-q1.rdf $RESDIR/queryt-e1.rdf > $RESDIR/diff-echo1.txt; else echo error with TRANSQ-ECHO1; fi if [ -s $RESDIR/queryt-e1.rdf ]; then diff $RESDIR/queryt-q1.rdf $RESDIR/queryt-e1.rdf > $RESDIR/diff-echo1.txt; else echo error with TRANSQ-ECHO1; fi
if [ ! -s $RESDIR/diff-echo1.txt ]; then echo error with TRANSQ-ECHO2; fi if [ ! -s $RESDIR/diff-echo1.txt ]; then echo error with TRANSQ-ECHO2; fi
java -cp $CP fr.inrialpes.exmo.align.cli.TransformQuery file://$CWD/examples/rdf/newsample.rdf --query $CWD/examples/rdf/query.sparql --echo > $RESDIR/queryt-e2.rdf java -cp $CP fr.inrialpes.exmo.align.cli.TransformQuery --alignment file://$CWD/examples/rdf/newsample.rdf --query $CWD/examples/rdf/query.sparql --echo > $RESDIR/queryt-e2.rdf
diff $RESDIR/queryt-e1.rdf $RESDIR/queryt-e2.rdf diff $RESDIR/queryt-e1.rdf $RESDIR/queryt-e2.rdf
#------------------- #-------------------
echo "\t-Dn=v (used for prefix)" echo "\t-Dn=v (used for prefix)"
java -cp $CP fr.inrialpes.exmo.align.cli.TransformQuery file://$CWD/examples/rdf/newsample.rdf -q $CWD/examples/rdf/query.sparql -Donto2=http://www.example.org/ontology2# -o $RESDIR/queryt-d1.rdf java -cp $CP fr.inrialpes.exmo.align.cli.TransformQuery -a file://$CWD/examples/rdf/newsample.rdf -q $CWD/examples/rdf/query.sparql -Donto2=http://www.example.org/ontology2# -o $RESDIR/queryt-d1.rdf
if [ -s $RESDIR/queryt-d1.rdf ]; then diff $RESDIR/queryt-q1.rdf $RESDIR/queryt-d1.rdf > $RESDIR/diff-prefix1.txt; else echo error with TRANSQ-PREFIX1; fi if [ -s $RESDIR/queryt-d1.rdf ]; then diff $RESDIR/queryt-q1.rdf $RESDIR/queryt-d1.rdf > $RESDIR/diff-prefix1.txt; else echo error with TRANSQ-PREFIX1; fi
if [ ! -s $RESDIR/diff-prefix1.txt ]; then echo error with TRANSQ-PREFIX2; fi if [ ! -s $RESDIR/diff-prefix1.txt ]; then echo error with TRANSQ-PREFIX2; fi
...@@ -1004,10 +1043,11 @@ echo "<?xml version='1.0' encoding='utf-8' standalone='no'?> ...@@ -1004,10 +1043,11 @@ echo "<?xml version='1.0' encoding='utf-8' standalone='no'?>
<properties> <properties>
<entry key=\"onto2\">http://www.example.org/ontology2#</entry> <entry key=\"onto2\">http://www.example.org/ontology2#</entry>
</properties>" > $RESDIR/params.xml </properties>" > $RESDIR/params.xml
java -cp $CP fr.inrialpes.exmo.align.cli.TransformQuery -P $RESDIR/params.xml file://$CWD/examples/rdf/newsample.rdf -q $CWD/examples/rdf/query.sparql -o $RESDIR/queryt-P1.rdf java -cp $CP fr.inrialpes.exmo.align.cli.TransformQuery -P $RESDIR/params.xml -a file://$CWD/examples/rdf/newsample.rdf -q $CWD/examples/rdf/query.sparql -o $RESDIR/queryt-P1.rdf
if [ -s $RESDIR/queryt-P1.rdf ]; then diff $RESDIR/queryt-P1.rdf $RESDIR/queryt-d1.rdf > $RESDIR/diff-prefix2.txt; else echo error with TRANSQ-PREFIX3; fi if [ -s $RESDIR/queryt-P1.rdf ]; then diff $RESDIR/queryt-P1.rdf $RESDIR/queryt-d1.rdf > $RESDIR/diff-prefix2.txt; else echo error with TRANSQ-PREFIX3; fi
if [ -s $RESDIR/diff-prefix2.txt ]; then echo error with TRANSQ-PREFIX4; fi if [ -s $RESDIR/diff-prefix2.txt ]; then echo error with TRANSQ-PREFIX4; fi
exit
######################################################################## ########################################################################
# AlignmentService # AlignmentService
######################################################################## ########################################################################
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment