Commit dac8ea4b authored by Christian Willms's avatar Christian Willms
Browse files

Added tests for ", < and > in xsd strings

parent 6e623fba
......@@ -7,6 +7,7 @@ import de.dfki.lt.hfc.qrelations.QRelationFactory;
import org.apache.commons.lang3.ArrayUtils;
// TO DO --- IMPLEMENTATION NOTE
//
// in order to implement SPARQL's
......@@ -140,7 +141,7 @@ public class Query {
where = where.trim(); // get rid of leading space
HashSet<String> foundVars = new HashSet<String>();
// Changed the regex to cover the intervals - CW
parseWhere(new StringTokenizer(where, " [](),?<>_\"\\", true), whereClauses, foundVars);
parseWhere(new StringTokenizer(where, " ?<>_\"\\", true), whereClauses, foundVars);
// some further checks on the projected vars, independent of optional filters
if (projectedVars.contains("*")) {
// a "*" should not come up with further vars
......
......@@ -1613,12 +1613,12 @@ public final class TupleStore {
// now gather potential additional information (XSD Type or language tag);
// the first whitespace char terminates XSD atom recognition
//
// type checking of XSD atoms should be implemented HERE -- use a seceond
// type checking of XSD atoms should be implemented HERE -- use a second
// string buffer to separate the bare atom from its type
boolean bareAtom = true;
while (st.hasMoreTokens()) {
token = st.nextToken();
if (token.equals(" "))
if (token.equals(" ") )
break;
else {
bareAtom = false;
......@@ -1626,9 +1626,6 @@ public final class TupleStore {
// normalize namespace
token = this.namespace.normalizeNamespaceUri(token);
sb.append(token);
// new condition TODO check wheter this is really needed
if (token.equals(">"))
break;
}
}
if (bareAtom) {
......
......@@ -137,27 +137,38 @@ public class QRelationFactory {
StringBuilder sb = new StringBuilder();
sb.append((isExclusive) ? "[" : "(");
String[] values = {"", ""};
int counter = 0;
boolean firstElement = true;
while (st.hasMoreTokens()) {
token = st.nextToken();
//System.out.println(token);
if (token.equals("]")) {
if (values[0].equals("") || values[1].equals(""))
throw new QueryParseException("An interval must consist of exactly two values! At least one is missing");
end = "]";
break;
} else if (token.equals(")")) {
if (values[0].equals("") || values[1].equals(""))
throw new QueryParseException("An interval must consist of exactly two values! At least one is missing");
end = ")";
break;
} else if (token.equals("\"")) {
values[counter] = tupleStore.parseAtom(st, tuple);
if (token.equals("\"")) {
//we need to add the trim to remove possible whitespaces at the end of the string.
String atom = tupleStore.parseAtom(st, tuple).trim();
if (atom.endsWith(",")){
if (!firstElement ) throw new QueryParseException("An interval must consist of exactly two values! ");
values[0] = atom.substring(0, atom.length()-1);
// it is also necessary to fix the corresponding tuple
tuple.set(tuple.size()-1, values[0]);
firstElement = false;
}
if (atom.endsWith(")")){
if (firstElement) throw new QueryParseException("An interval must consist of exactly two values! At least one is missing");
values[1] = atom.substring(0, atom.length()-1);
// it is also necessary to fix the corresponding tuple
tuple.set(tuple.size()-1, values[1]);
end = ")";
break;
}
if (atom.endsWith("]")){
if (firstElement) throw new QueryParseException("An interval must consist of exactly two values! At least one is missing");
values[1] = atom.substring(0, atom.length()-1);
// it is also necessary to fix the corresponding tuple
tuple.set(tuple.size()-1, values[1]);
end = "]";
break;
}
tupleStore.putObject(values[counter]);
} else if (token.equals(",")) {
if (values[0].equals("") || counter == 1)
throw new QueryParseException("An interval must consist of exactly two values! ");
counter++;
} else if (token.equals(" ")) // keep on parsing ...
continue;
}
......
<test:a1> <test:value> "foo"^^<xsd:string> .
<test:a2> <test:value> "fo\o"^^<xsd:string> .
<test:a3> <test:value> "fo_|o"^^<xsd:string> .
<test:a4> <test:value> "fo o"^^<xsd:string> .
<test:a5> <test:value> "fo<o"^^<xsd:string> .
<test:a6> <test:value> "fo>o"^^<xsd:string> .
<test:a7> <test:value> "f<oo>"^^<xsd:string> .
<test:a8> <test:value> "f<"o"o"^^<xsd:string> .
<test:a9> <test:value> "fo<o"^^<xsd:string> .
<test:a10> <test:value> "f<"">o"o"^^<xsd:string> .
\ No newline at end of file
......@@ -7,6 +7,7 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import org.junit.Assert;
import org.junit.Test;
......@@ -184,6 +185,30 @@ public class TupleStoreTest {
assertTrue(TupleStore.isConstant(1));
}
@Test
public void testParseAtom() throws IOException, WrongFormatException, QueryParseException {
TupleStore objectToTest = new TupleStore(1,1);
objectToTest.verbose = true;
objectToTest.readTuples(getTestResource("ReadTest", "testAtoms.nt"));
assertEquals("Expected 10 atoms but was " + objectToTest.getAllTuples().size(), 10, objectToTest.getAllTuples().size());
String[][] expected = {
{ "\"foo\"^^<xsd:string>" },
{ "\"fo\\o\"^^<xsd:string>" },
{ "\"fo_|o\"^^<xsd:string>" },
{ "\"fo o\"^^<xsd:string>" },
{ "\"fo<o\"^^<xsd:string>" },
{ "\"fo>o\"^^<xsd:string>" },
{ "\"f<oo>\"^^<xsd:string>" },
{ "\"f<\"o\"o\"^^<xsd:string>" },
{ "\"fo<o\"^^<xsd:string>" },
{ "\"f<\"\">o\"o\"^^<xsd:string>" }
};
Query q = new Query(objectToTest);
BindingTable bt = q.query("SELECT ?o WHERE ?s <test:value> ?o");
checkResult(expected, bt, "?o");
}
@Test
public void testinternalizeTuple1() {
TupleStore objectfortest = new TupleStore(4, 2);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment