Search in sources :

Example 31 with FieldQuery

use of org.apache.stanbol.entityhub.servicesapi.query.FieldQuery in project stanbol by apache.

the class YardTest method testFindRepresentationText.

/**
     * Same as {@link #testFindText()} but using 
     * {@link Yard#findRepresentation(FieldQuery)} to execute the queries
     */
@Test
public void testFindRepresentationText() {
    //init the test data
    FieldQueryTestData data = getFieldQueryTestData();
    //query for all languages and value1
    FieldQuery query = getYard().getQueryFactory().createFieldQuery();
    query.setConstraint(data.textField, new TextConstraint(data.textValue1.getText()));
    validateQueryResults(query, getYard().findRepresentation(query), Arrays.asList(data.r1.getId(), data.r1en.getId(), data.r1de.getId()), Arrays.asList(data.textField, data.refField, data.intField));
    //same for value2
    query = getYard().getQueryFactory().createFieldQuery();
    query.setConstraint(data.textField, new TextConstraint(data.textValue2.getText()));
    validateQueryResults(query, getYard().findRepresentation(query), Arrays.asList(data.r2.getId(), data.r2en.getId(), data.r2de.getId()), Arrays.asList(data.textField, data.refField, data.intField));
}
Also used : FieldQuery(org.apache.stanbol.entityhub.servicesapi.query.FieldQuery) TextConstraint(org.apache.stanbol.entityhub.servicesapi.query.TextConstraint) Test(org.junit.Test)

Example 32 with FieldQuery

use of org.apache.stanbol.entityhub.servicesapi.query.FieldQuery in project stanbol by apache.

the class YardTest method testQeuryFactory.

/*
     * All the follow up tests where added as part of STANBOL-1202
     */
/**
     * Simple test for the QueryFactory
     */
@Test
public void testQeuryFactory() {
    FieldQueryFactory qf = getYard().getQueryFactory();
    Assert.assertNotNull("The getter for the FieldQueryFactory MUST NOT return NULL!", qf);
    FieldQuery query = qf.createFieldQuery();
    Assert.assertNotNull("The FieldQueryFactory returned NULL as query", query);
}
Also used : FieldQuery(org.apache.stanbol.entityhub.servicesapi.query.FieldQuery) FieldQueryFactory(org.apache.stanbol.entityhub.servicesapi.query.FieldQueryFactory) Test(org.junit.Test)

Example 33 with FieldQuery

use of org.apache.stanbol.entityhub.servicesapi.query.FieldQuery in project stanbol by apache.

the class YardTest method testFindTextOfLanguage.

/**
     * Test a simple {@link TextConstraint} for any language
     */
@Test
public void testFindTextOfLanguage() {
    //init the test data
    FieldQueryTestData data = getFieldQueryTestData();
    //value1@en
    FieldQuery query = getYard().getQueryFactory().createFieldQuery();
    query.setConstraint(data.textField, new TextConstraint(data.textValue1.getText(), "en"));
    query.addSelectedField(data.textField);
    query.addSelectedField(data.refField);
    validateQueryResults(query, getYard().find(query), Arrays.asList(data.r1en.getId()), Arrays.asList(data.textField, data.refField));
    //value2@de
    query = getYard().getQueryFactory().createFieldQuery();
    query.setConstraint(data.textField, new TextConstraint(data.textValue2.getText(), "de"));
    query.addSelectedField(data.textField);
    query.addSelectedField(data.refField);
    validateQueryResults(query, getYard().find(query), Arrays.asList(data.r2de.getId()), Arrays.asList(data.textField, data.refField));
    //value1@null
    query = getYard().getQueryFactory().createFieldQuery();
    query.setConstraint(data.textField, new TextConstraint(data.textValue1.getText(), (String) null));
    query.addSelectedField(data.textField);
    query.addSelectedField(data.refField);
    validateQueryResults(query, getYard().find(query), Arrays.asList(data.r1.getId()), Arrays.asList(data.textField, data.refField));
    //value1@null,en
    query = getYard().getQueryFactory().createFieldQuery();
    query.setConstraint(data.textField, new TextConstraint(data.textValue1.getText(), null, "en"));
    query.addSelectedField(data.textField);
    query.addSelectedField(data.refField);
    validateQueryResults(query, getYard().find(query), Arrays.asList(data.r1.getId(), data.r1en.getId()), Arrays.asList(data.textField, data.refField));
    //value1@en,de
    query = getYard().getQueryFactory().createFieldQuery();
    query.setConstraint(data.textField, new TextConstraint(data.textValue1.getText(), "en", "de"));
    query.addSelectedField(data.textField);
    query.addSelectedField(data.refField);
    validateQueryResults(query, getYard().find(query), Arrays.asList(data.r1en.getId(), data.r1de.getId()), Arrays.asList(data.textField, data.refField));
}
Also used : FieldQuery(org.apache.stanbol.entityhub.servicesapi.query.FieldQuery) TextConstraint(org.apache.stanbol.entityhub.servicesapi.query.TextConstraint) Test(org.junit.Test)

Example 34 with FieldQuery

use of org.apache.stanbol.entityhub.servicesapi.query.FieldQuery in project stanbol by apache.

the class YardTest method testFindValues.

/**
     * Tests simple {@link ValueConstraint}s
     */
@Test
public void testFindValues() {
    //init the test data
    FieldQueryTestData data = getFieldQueryTestData();
    //query for all languages and value1
    FieldQuery query = getYard().getQueryFactory().createFieldQuery();
    query.setConstraint(data.intField, new ValueConstraint(data.intValue1));
    query.addSelectedField(data.intField);
    query.addSelectedField(data.textField);
    validateQueryResults(query, getYard().find(query), Arrays.asList(data.r1.getId(), data.r1en.getId(), data.r1de.getId()), Arrays.asList(data.intField, data.textField));
    //same for value2
    query = getYard().getQueryFactory().createFieldQuery();
    query.setConstraint(data.intField, new ValueConstraint(data.intValue2));
    query.addSelectedField(data.intField);
    query.addSelectedField(data.textField);
    validateQueryResults(query, getYard().find(query), Arrays.asList(data.r2.getId(), data.r2en.getId(), data.r2de.getId()), Arrays.asList(data.intField, data.textField));
}
Also used : FieldQuery(org.apache.stanbol.entityhub.servicesapi.query.FieldQuery) ValueConstraint(org.apache.stanbol.entityhub.servicesapi.query.ValueConstraint) Test(org.junit.Test)

Example 35 with FieldQuery

use of org.apache.stanbol.entityhub.servicesapi.query.FieldQuery in project stanbol by apache.

the class YardTest method testFindText.

/**
     * Test a simple {@link TextConstraint} for any language
     */
@Test
public void testFindText() {
    //init the test data
    FieldQueryTestData data = getFieldQueryTestData();
    //query for all languages and value1
    FieldQuery query = getYard().getQueryFactory().createFieldQuery();
    query.setConstraint(data.textField, new TextConstraint(data.textValue1.getText()));
    query.addSelectedField(data.textField);
    query.addSelectedField(data.refField);
    validateQueryResults(query, getYard().find(query), Arrays.asList(data.r1.getId(), data.r1en.getId(), data.r1de.getId()), Arrays.asList(data.textField, data.refField));
    //same for value2
    query = getYard().getQueryFactory().createFieldQuery();
    query.setConstraint(data.textField, new TextConstraint(data.textValue2.getText()));
    query.addSelectedField(data.textField);
    query.addSelectedField(data.refField);
    validateQueryResults(query, getYard().find(query), Arrays.asList(data.r2.getId(), data.r2en.getId(), data.r2de.getId()), Arrays.asList(data.textField, data.refField));
}
Also used : FieldQuery(org.apache.stanbol.entityhub.servicesapi.query.FieldQuery) TextConstraint(org.apache.stanbol.entityhub.servicesapi.query.TextConstraint) Test(org.junit.Test)

Aggregations

FieldQuery (org.apache.stanbol.entityhub.servicesapi.query.FieldQuery)41 TextConstraint (org.apache.stanbol.entityhub.servicesapi.query.TextConstraint)18 Test (org.junit.Test)13 Representation (org.apache.stanbol.entityhub.servicesapi.model.Representation)12 ReferenceConstraint (org.apache.stanbol.entityhub.servicesapi.query.ReferenceConstraint)10 HashSet (java.util.HashSet)8 ArrayList (java.util.ArrayList)7 Site (org.apache.stanbol.entityhub.servicesapi.site.Site)6 QueryResultListImpl (org.apache.stanbol.entityhub.core.query.QueryResultListImpl)5 Entity (org.apache.stanbol.entityhub.servicesapi.model.Entity)5 SiteException (org.apache.stanbol.entityhub.servicesapi.site.SiteException)5 Constraint (org.apache.stanbol.entityhub.servicesapi.query.Constraint)4 FieldQueryFactory (org.apache.stanbol.entityhub.servicesapi.query.FieldQueryFactory)4 ValueConstraint (org.apache.stanbol.entityhub.servicesapi.query.ValueConstraint)4 Text (org.apache.stanbol.entityhub.servicesapi.model.Text)3 SimilarityConstraint (org.apache.stanbol.entityhub.servicesapi.query.SimilarityConstraint)3 JSONException (org.codehaus.jettison.json.JSONException)3 JSONObject (org.codehaus.jettison.json.JSONObject)3 IOException (java.io.IOException)2 PrivilegedActionException (java.security.PrivilegedActionException)2