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;
}
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;
}
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));
}
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));
}
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;
}
Aggregations