SPARQLQuery implements Cloneable, Serializable { @Override public Object clone() throws CloneNotSupportedException { SPARQLQuery q = new SPARQLQuery(); q.isASKQuery(isASKQuery); q.constraintTriples = Lists.newArrayList(); for (String constraint : this.constraintTriples) { q.constraintTriples.add(constraint); } q.filter = Sets.newHashSet(); for (String key : this.filter) { q.filter.add(key); } q.textMapFromVariableToSingleFuzzyToken = Maps.newHashMap(); for (String key : this.textMapFromVariableToSingleFuzzyToken.keySet()) { Set<String> list = Sets.newHashSet(this.textMapFromVariableToSingleFuzzyToken.get(key)); q.textMapFromVariableToSingleFuzzyToken.put(key, list); } q.textMapFromVariableToCombinedNNExactMatchToken = Maps.newHashMap(); for (String key : this.textMapFromVariableToCombinedNNExactMatchToken.keySet()) { Set<String> list = Sets.newHashSet(this.textMapFromVariableToCombinedNNExactMatchToken.get(key)); q.textMapFromVariableToCombinedNNExactMatchToken.put(key, list); } return q; } SPARQLQuery(final String initialConstraint);  SPARQLQuery(); void isASKQuery(final boolean isASKQuery); void addConstraint(final String constraint); void addFilterOverAbstractsContraint(final String variable, final String label); boolean constraintsContains(final String target); void addFilter(final String string); @Override Object clone(); @Override String toString(); Set<String> generateQueries(); void setLimit(final int cardinality); public List<String> constraintTriples; public Set<String> filter; public Map<String, Set<String>> textMapFromVariableToSingleFuzzyToken; public Map<String, Set<String>> textMapFromVariableToCombinedNNExactMatchToken; }
@Test public void cloneTest() throws CloneNotSupportedException { SPARQLQuery query = new SPARQLQuery(); query.addConstraint("?proj a <http: query.addFilterOverAbstractsContraint("?prof", "Mandela anti-apartheid activist"); String realAnswer = "PREFIX text:<http: "SELECT DISTINCT ?proj WHERE {\n" + "?prof text:query (<http: "?proj a <http: "}\n" + "LIMIT 1"; SPARQLQuery answer = (SPARQLQuery) query.clone(); Assert.assertTrue("Clone differs from real answer.", realAnswer.equals(answer.toString())); }