Search in sources :

Example 6 with AnnisAttribute

use of annis.service.objects.AnnisAttribute in project ANNIS by korpling.

the class FlatQueryBuilder method getAvailableAnnotationNames.

public Set<String> getAvailableAnnotationNames() {
    Set<String> result = new TreeSet<>();
    WebResource service = Helper.getAnnisWebResource();
    // get current corpus selection
    Set<String> corpusSelection = cp.getState().getSelectedCorpora().getValue();
    if (service != null) {
        try {
            List<AnnisAttribute> atts = new LinkedList<>();
            for (String corpus : corpusSelection) {
                atts.addAll(service.path("query").path("corpora").path(corpus).path("annotations").queryParam("fetchvalues", "false").queryParam("onlymostfrequentvalues", "false").get(new GenericType<List<AnnisAttribute>>() {
                }));
            }
            for (AnnisAttribute a : atts) {
                if (a.getType() == AnnisAttribute.Type.node) {
                    result.add(killNamespace(a.getName()));
                }
            }
        } catch (ClientHandlerException ex) {
            log.error(null, ex);
        } catch (UniformInterfaceException ex) {
            log.error(null, ex);
        }
    }
    result.add("tok");
    return result;
}
Also used : ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) GenericType(com.sun.jersey.api.client.GenericType) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) TreeSet(java.util.TreeSet) AnnisAttribute(annis.service.objects.AnnisAttribute) WebResource(com.sun.jersey.api.client.WebResource) LinkedList(java.util.LinkedList)

Example 7 with AnnisAttribute

use of annis.service.objects.AnnisAttribute in project ANNIS by korpling.

the class FlatQueryBuilder method getAvailableMetaNames.

public Set<String> getAvailableMetaNames() {
    Set<String> result = new TreeSet<>();
    WebResource service = Helper.getAnnisWebResource();
    // get current corpus selection
    Set<String> corpusSelection = cp.getState().getSelectedCorpora().getValue();
    if (service != null) {
        try {
            List<AnnisAttribute> atts = new LinkedList<>();
            for (String corpus : corpusSelection) {
                atts.addAll(service.path("query").path("corpora").path(corpus).path("annotations").get(new GenericType<List<AnnisAttribute>>() {
                }));
            }
            for (AnnisAttribute a : atts) {
                if (a.getType() == AnnisAttribute.Type.meta) {
                    String aa = killNamespace(a.getName());
                    result.add(aa);
                }
            }
        } catch (ClientHandlerException ex) {
            log.error(null, ex);
        } catch (UniformInterfaceException ex) {
            log.error(null, ex);
        }
    }
    return result;
}
Also used : ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) GenericType(com.sun.jersey.api.client.GenericType) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) TreeSet(java.util.TreeSet) AnnisAttribute(annis.service.objects.AnnisAttribute) WebResource(com.sun.jersey.api.client.WebResource) LinkedList(java.util.LinkedList)

Example 8 with AnnisAttribute

use of annis.service.objects.AnnisAttribute in project ANNIS by korpling.

the class TestListAnnotationsSqlHelper method extractDataNoValues.

@SuppressWarnings("unchecked")
@Test
public void extractDataNoValues() throws SQLException {
    // stub a result set with 2 annotations with NULL value set
    ResultSet resultSet = mock(ResultSet.class);
    when(resultSet.next()).thenReturn(true, true, false);
    when(resultSet.getString("name")).thenReturn(NAME1, NAME2);
    when(resultSet.getString("value")).thenReturn(NULL);
    // expected
    AnnisAttribute attribute1 = newNamedAnnisAttribute(NAME1);
    AnnisAttribute attribute2 = newNamedAnnisAttribute(NAME2);
    // call and test
    List<AnnisAttribute> annotations = (List<AnnisAttribute>) listNodeAnnotationsSqlHelper.extractData(resultSet);
    assertThat(annotations, size(2));
    assertThat(annotations, hasItems(attribute1, attribute2));
}
Also used : AnnisAttribute(annis.service.objects.AnnisAttribute) ResultSet(java.sql.ResultSet) List(java.util.List) Test(org.junit.Test)

Example 9 with AnnisAttribute

use of annis.service.objects.AnnisAttribute in project ANNIS by korpling.

the class TestListAnnotationsSqlHelper method extractDataWithValues.

@SuppressWarnings("unchecked")
@Test
public void extractDataWithValues() throws SQLException {
    // stub a result set with 5 rows
    // row 1 - 3: annotation with 3 values
    // row 4: annotation with 1 value
    // row 5: annotation with no values
    ResultSet resultSet = mock(ResultSet.class);
    when(resultSet.next()).thenReturn(true, true, true, true, true, false);
    // row 1 - 3: annotation with 3 values
    when(resultSet.getString("name")).thenReturn(NAME1, NAME1, NAME1, NAME2, NAME3);
    when(resultSet.getString("value")).thenReturn(VALUE1, VALUE2, VALUE3, VALUE1, NULL);
    // expected
    AnnisAttribute attribute1 = newNamedAnnisAttribute(NAME1, VALUE1, VALUE2, VALUE3);
    AnnisAttribute attribute2 = newNamedAnnisAttribute(NAME2, VALUE1);
    AnnisAttribute attribute3 = newNamedAnnisAttribute(NAME3);
    // call and test
    List<AnnisAttribute> annotations = (List<AnnisAttribute>) listNodeAnnotationsSqlHelper.extractData(resultSet);
    assertThat(annotations, size(3));
    assertThat(annotations, hasItems(attribute1, attribute2, attribute3));
}
Also used : AnnisAttribute(annis.service.objects.AnnisAttribute) ResultSet(java.sql.ResultSet) List(java.util.List) Test(org.junit.Test)

Example 10 with AnnisAttribute

use of annis.service.objects.AnnisAttribute in project ANNIS by korpling.

the class TestListAnnotationsSqlHelper method newNamedAnnisAttribute.

// /// private helper
private AnnisAttribute newNamedAnnisAttribute(String name, String... values) {
    AnnisAttribute attribute = new AnnisAttribute();
    attribute.setName(name);
    for (String value : values) attribute.addValue(value);
    return attribute;
}
Also used : AnnisAttribute(annis.service.objects.AnnisAttribute)

Aggregations

AnnisAttribute (annis.service.objects.AnnisAttribute)15 LinkedList (java.util.LinkedList)10 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)9 WebResource (com.sun.jersey.api.client.WebResource)9 ClientHandlerException (com.sun.jersey.api.client.ClientHandlerException)7 TreeSet (java.util.TreeSet)7 GenericType (com.sun.jersey.api.client.GenericType)5 AnnisQLSemanticsException (annis.exceptions.AnnisQLSemanticsException)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 AnnisCorpusAccessException (annis.exceptions.AnnisCorpusAccessException)2 AnnisQLSyntaxException (annis.exceptions.AnnisQLSyntaxException)2 QueryNode (annis.model.QueryNode)2 Match (annis.service.objects.Match)2 MatchGroup (annis.service.objects.MatchGroup)2 SubgraphFilter (annis.service.objects.SubgraphFilter)2 Stopwatch (com.google.common.base.Stopwatch)2 BufferedReader (java.io.BufferedReader)2