Commit 3bcffd33 authored by Christian Willms's avatar Christian Willms
Browse files

Fix bug in Equals and add test

parent 32f2d38a
package de.dfki.lt.hfc.operators;
import de.dfki.lt.hfc.FunctionalOperator;
/**
* checks whether the first argument contains the second argument;
* arguments are assumed to be strings of type xsd:string
*
* @see FunctionalOperator
*
* @author (C) Hans-Ulrich Krieger
* @since JDK 1.5
* @version Wed Jun 23 11:04:27 CEST 2010
*/
public final class Equals extends FunctionalOperator {
/**
* note that apply() does NOT check at the moment whether the int args
* represent in fact XSD strings (and not URIs, XSD ints, etc.);
* note that apply() does NOT check whether it is given exactly two arguments
*
* @return FunctionalOperator.TRUE or FunctionalOperator.FALSE
*/
public int apply(int[] args) {
if (getObject(args[0]).equals(getObject(args[1])))
return FunctionalOperator.TRUE;
else
return FunctionalOperator.FALSE;
}
}
......@@ -133,4 +133,25 @@ public final class XsdString extends XsdAnySimpleType {
return this.value.compareTo(((XsdString) o).value);
}
/** Two XsdString objects are equal if value and language tag are equal
*/
public boolean equals(Object o) {
if (o instanceof String)
return this.languageTag == null && value.equals(o);
if (o instanceof XsdString) {
XsdString s = (XsdString)o;
if (this.languageTag == null) {
return s.languageTag == null && this.value.equals(s.value);
} else {
return this.languageTag.equals(s.languageTag)
&& this.value.equals(s.value);
}
}
return false;
}
public int hashCode() {
return this.value.hashCode()
+ (this.languageTag == null ? 0 : 29 * this.languageTag.hashCode());
}
}
xsd http://www.w3.org/2001/XMLSchema#
rdf = http://www.w3.org/1999/02/22-rdf-syntax-ns#
rdfs = http://www.w3.org/2000/01/rdf-schema#
owl = http://www.w3.org/2002/07/owl#
logic http://www.dfki.de/lt/onto/common/logic.owl#
dom http://www.dfki.de/lt/onto/pal/domain.owl#
pal http://www.dfki.de/lt/onto/pal/pal.owl#
<dom:val0> <dom:prof> "abc"@en "1"^^<xsd:long> .
<dom:val1> <dom:prof> "def"@en "2"^^<xsd:long> .
<dom:val2> <dom:prof> "abc"@nl "3"^^<xsd:long> .
<dom:val3> <dom:prof> "def"@nl "4"^^<xsd:long> .
<dom:val4> <dom:prof> "abc"^^<xsd:string> "5"^^<xsd:long> .
<dom:val5> <dom:prof> "abc" "6"^^<xsd:long> .
<dom:val6> <dom:prof> "def"^^<xsd:string> "7"^^<xsd:long> .
<dom:val7> <dom:prof> "def" "8"^^<xsd:long> .
package de.dfki.lt.hfc.operators;
import static de.dfki.lt.hfc.Utils.*;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.junit.BeforeClass;
import org.junit.Test;
import de.dfki.lt.hfc.*;
public class LEqualsTest {
static TupleStore ts;
static Query q;
public static String getResource(String name) {
return getTestResource("Equals", name);
}
@BeforeClass
public static void init() throws FileNotFoundException, WrongFormatException, IOException {
Namespace ns = new Namespace(getResource("namespaces.ns"), false);
ts = new TupleStore(1000, 5000, ns);
ts.verbose = false;
ts.readTuples(getResource("tuples.nt"));
q = new Query(ts);
}
@Test
public void testEquals1() throws QueryParseException {
BindingTable bt = q.query("SELECT ?o WHERE ?o <dom:prof> ?s ?_ "
+ " FILTER Equals ?s \"abc\"@en");
String[][] expected = {{"<dom:val0>"}};
checkResult(expected, bt, bt.getVars());
}
@Test
public void testEquals2() throws QueryParseException {
BindingTable bt = q.query("SELECT ?o WHERE ?o <dom:prof> ?s ?_ "
+ " FILTER Equals ?s \"def\"@en");
String[][] expected2 = {{"<dom:val1>"}};
checkResult(expected2, bt, bt.getVars());
}
@Test
public void testEquals3() throws QueryParseException {
BindingTable bt = q.query("SELECT ?o WHERE ?o <dom:prof> ?s ?_ "
+ " FILTER Equals ?s \"def\"@nl");
String[][] expected3 = {{"<dom:val3>"}};
checkResult(expected3, bt, bt.getVars());
}
@Test
public void testEquals4() throws QueryParseException {
BindingTable bt = q.query("SELECT ?o WHERE ?o <dom:prof> ?s ?_ "
+ " FILTER Equals ?s \"def\"");
String[][] expected4 = {{"<dom:val6>"}, {"<dom:val7>"}};
checkResult(expected4, bt, bt.getVars());
}
@Test
public void testEquals5() throws QueryParseException {
BindingTable bt = q.query("SELECT ?o WHERE ?o <dom:prof> ?s ?_ "
+ " FILTER Equals ?s \"abc\"");
String[][] expected5 = {{"<dom:val4>"}, {"<dom:val5>"}};
checkResult(expected5, bt, bt.getVars());
}
}
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