use of org.apache.stanbol.entityhub.servicesapi.query.FieldQuery in project stanbol by apache.
the class YardTest method testFindRange.
/**
* Tests simple {@link RangeConstraint}
*/
@Test
public void testFindRange() {
//init the test data
FieldQueryTestData data = getFieldQueryTestData();
//query for all languages and value1
FieldQuery query = getYard().getQueryFactory().createFieldQuery();
query.setConstraint(data.intField, new RangeConstraint(data.intValue2, data.intValue5, true));
query.addSelectedField(data.intField);
query.addSelectedField(data.refField);
validateQueryResults(query, getYard().find(query), Arrays.asList(data.r2.getId(), data.r2en.getId(), data.r2de.getId(), data.r5.getId()), Arrays.asList(data.intField, data.refField));
//same for value2
query = getYard().getQueryFactory().createFieldQuery();
query.setConstraint(data.intField, new RangeConstraint(data.intValue2, data.intValue10, false));
query.addSelectedField(data.intField);
query.addSelectedField(data.textField);
validateQueryResults(query, getYard().find(query), Arrays.asList(data.r5.getId()), Arrays.asList(data.intField, data.textField));
}
use of org.apache.stanbol.entityhub.servicesapi.query.FieldQuery in project stanbol by apache.
the class YardTest method testfindOptionalTexts.
/**
* Tests a TextConstraint with multiple optional values
*/
@Test
public void testfindOptionalTexts() {
//init the test data
FieldQueryTestData data = getFieldQueryTestData();
//value1@en || value2@en
FieldQuery query = getYard().getQueryFactory().createFieldQuery();
query.setConstraint(data.textField, new TextConstraint(Arrays.asList(data.textValue1.getText(), data.textValue2.getText()), "en"));
query.addSelectedField(data.textField);
query.addSelectedField(data.refField);
validateQueryResults(query, getYard().find(query), Arrays.asList(data.r1en.getId(), data.r2en.getId()), Arrays.asList(data.textField, data.refField));
//value1@en,de || value2@en,de
query = getYard().getQueryFactory().createFieldQuery();
query.setConstraint(data.textField, new TextConstraint(Arrays.asList(data.textValue1.getText(), data.textValue2.getText()), "en", "de"));
query.addSelectedField(data.textField);
query.addSelectedField(data.refField);
validateQueryResults(query, getYard().find(query), Arrays.asList(data.r1en.getId(), data.r1de.getId(), data.r2en.getId(), data.r2de.getId()), Arrays.asList(data.textField, data.refField));
}
use of org.apache.stanbol.entityhub.servicesapi.query.FieldQuery in project stanbol by apache.
the class SiteManagerImpl method find.
@Override
public QueryResultList<Representation> find(FieldQuery query) {
log.debug("find with query{}", query);
Set<Representation> representations = new HashSet<Representation>();
//TODO: The QueryResultList expects that the query as executed is added
//to the response. However when executing queries on multiple site they
//might support a different set of features and therefore execute
//different variants. For now I return simple the query as executed by
//the first Site that contributes results
FieldQuery processedQuery = null;
FieldQuery queryWithResults = null;
for (Site site : referencedSites) {
if (site.supportsSearch()) {
log.debug(" > query site {}", site.getId());
try {
QueryResultList<Representation> results = site.find(query);
if (processedQuery == null) {
processedQuery = results.getQuery();
}
if (!results.isEmpty() && queryWithResults == null) {
processedQuery = results.getQuery();
}
for (Representation rep : results) {
if (!representations.contains(rep)) {
//do not override
representations.add(rep);
} else {
log.info("Entity {} found on more than one Referenced Site" + " -> Representation of Site {} is ignored", rep.getId(), site.getConfiguration().getName());
}
}
} catch (SiteException e) {
log.warn("Unable to access Site " + site.getConfiguration().getName() + " (id = " + site.getId() + ")", e);
}
} else {
log.debug(" > Site {} does not support queries", site.getId());
}
}
return new QueryResultListImpl<Representation>(//use the query with results
queryWithResults != null ? //use the query with results
queryWithResults : //if not a processed
processedQuery != null ? //if not a processed
processedQuery : //else the parsed one
query, representations, Representation.class);
}
use of org.apache.stanbol.entityhub.servicesapi.query.FieldQuery in project stanbol by apache.
the class ClerezzaModelWriter method write.
@Override
public void write(QueryResultList<?> result, OutputStream out, MediaType mediaType) throws WebApplicationException, IOException {
Graph queryRdf = toRDF(result);
//we need also to the JSON formatted FieldQuery as a literal to the
//RDF data.
FieldQuery query = result.getQuery();
if (query != null) {
try {
JSONObject fieldQueryJson = FieldQueryToJsonUtils.toJSON(query, nsPrefixService);
if (fieldQueryJson != null) {
//add the triple with the fieldQuery
queryRdf.add(new TripleImpl(QUERY_RESULT_LIST, FIELD_QUERY, literalFactory.createTypedLiteral(fieldQueryJson.toString())));
}
} catch (JSONException e) {
log.warn(String.format("Unable to serialize Fieldquery '%s' to JSON! " + "Query response will not contain the serialized query.", query), e);
}
}
//now serialise the data
writeRdf(queryRdf, out, mediaType);
}
use of org.apache.stanbol.entityhub.servicesapi.query.FieldQuery in project stanbol by apache.
the class SesameModelWriter method write.
@Override
public void write(QueryResultList<?> result, OutputStream out, MediaType mediaType) throws WebApplicationException, IOException {
Model queryRdf = toRDF(result);
//we need also to the JSON formatted FieldQuery as a literal to the
//RDF data.
FieldQuery query = result.getQuery();
if (query != null) {
try {
JSONObject fieldQueryJson = FieldQueryToJsonUtils.toJSON(query, nsPrefixService);
if (fieldQueryJson != null) {
//add the triple with the fieldQuery
queryRdf.add(QUERY_RESULT_LIST, FIELD_QUERY, sesameFactory.createLiteral(fieldQueryJson.toString()));
}
} catch (JSONException e) {
log.warn(String.format("Unable to serialize Fieldquery '%s' to JSON! " + "Query response will not contain the serialized query.", query), e);
}
}
//now serialise the data
writeRdf(queryRdf, out, mediaType);
}
Aggregations