use of annis.service.objects.MatchGroup in project ANNIS by korpling.
the class PlainTextMatchGroupProvider method readFrom.
@Override
public MatchGroup readFrom(Class<MatchGroup> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
String val = CharStreams.toString(new InputStreamReader(entityStream, Charsets.UTF_8));
MatchGroup result = MatchGroup.parseString(val);
return result;
}
use of annis.service.objects.MatchGroup in project ANNIS by korpling.
the class LegacyGraphConverterTest method testConvertToAOM.
/**
* Test of convertToAOM method, of class LegacyGraphConverter.
*/
@Test
public void testConvertToAOM() throws SQLException {
SaltAnnotateExtractor saltExtractor = new SaltAnnotateExtractor() {
@Override
protected SolutionKey<?> createSolutionKey() {
PostgreSqlArraySolutionKey<Long> key = new PostgreSqlArraySolutionKey<>();
key.setKeyColumnName("key");
key.setIdColumnName("id");
return key;
}
};
CorpusPathExtractor corpusPathExtractor = new ArrayCorpusPathExtractor();
saltExtractor.setCorpusPathExtractor(corpusPathExtractor);
TestAnnotateSqlGenerator.setupOuterQueryFactsTableColumnAliases(saltExtractor);
List<Match> matches = new ArrayList<>();
matches.add(Match.parseFromString("salt:/pcc2/4282/#tok_155 tiger::pos::salt:/pcc2/4282#tok_156"));
MatchGroup matchGroup = new MatchGroup(matches);
SaltProject p = saltExtractor.extractData(new CsvResultSetProvider(annis.sqlgen.SaltAnnotateExtractorTest.class.getResourceAsStream("SampleAnnotateResult.csv")).getResultSet());
SaltAnnotateExtractor.addMatchInformation(p, matchGroup);
List<AnnotationGraph> expected = aomSqlGen.extractData(new CsvResultSetProvider(annis.sqlgen.SaltAnnotateExtractorTest.class.getResourceAsStream("SampleAnnotateResult.csv")).getResultSet());
List<AnnotationGraph> result = LegacyGraphConverter.convertToAOM(p);
assertEquals(expected.size(), result.size());
Iterator<AnnotationGraph> itGraphExpected = expected.iterator();
Iterator<AnnotationGraph> itGraphResult = result.iterator();
while (itGraphExpected.hasNext() && itGraphResult.hasNext()) {
AnnotationGraph graphExpected = itGraphExpected.next();
AnnotationGraph graphResult = itGraphResult.next();
List<AnnisNode> nodeListExpected = graphExpected.getNodes();
List<AnnisNode> nodeListResult = graphResult.getNodes();
assertEquals(nodeListExpected.size(), nodeListResult.size());
Collections.sort(nodeListExpected, new Comparator<AnnisNode>() {
@Override
public int compare(AnnisNode arg0, AnnisNode arg1) {
return Long.valueOf(arg0.getId()).compareTo(Long.valueOf(arg1.getId()));
}
});
Collections.sort(nodeListResult, new Comparator<AnnisNode>() {
@Override
public int compare(AnnisNode arg0, AnnisNode arg1) {
return Long.valueOf(arg0.getId()).compareTo(Long.valueOf(arg1.getId()));
}
});
Iterator<AnnisNode> itNodeExpected = nodeListExpected.iterator();
Iterator<AnnisNode> itNodeResult = nodeListResult.iterator();
while (itNodeExpected.hasNext() && itNodeResult.hasNext()) {
checkAnnisNodeEqual(itNodeExpected.next(), itNodeResult.next());
}
}
}
use of annis.service.objects.MatchGroup in project ANNIS by korpling.
the class QueryServiceImpl method find.
@GET
@Path("search/find")
@Produces({ "application/xml", "text/plain" })
@Override
public Response find(@QueryParam("q") String query, @QueryParam("corpora") String rawCorpusNames, @DefaultValue("0") @QueryParam("offset") String offsetRaw, @DefaultValue("-1") @QueryParam("limit") String limitRaw, @DefaultValue("ascending") @QueryParam("order") String orderRaw) throws IOException {
requiredParameter(query, "q", "AnnisQL query");
requiredParameter(rawCorpusNames, "corpora", "comma separated list of corpus names");
Subject user = SecurityUtils.getSubject();
List<String> corpusNames = splitCorpusNamesFromRaw(rawCorpusNames);
for (String c : corpusNames) {
user.checkPermission("query:find:" + c);
}
int offset = Integer.parseInt(offsetRaw);
int limit = Integer.parseInt(limitRaw);
OrderType order;
try {
order = OrderType.valueOf(orderRaw.toLowerCase());
} catch (IllegalArgumentException ex) {
throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).type(MediaType.TEXT_PLAIN).entity("parameter 'order' has the invalid value '" + orderRaw + "'. It should be one of" + " 'ascending', 'random' or 'descending").build());
}
final QueryData data = queryDataFromParameters(query, rawCorpusNames);
data.setCorpusConfiguration(queryDao.getCorpusConfiguration());
data.addExtension(new LimitOffsetQueryData(offset, limit, order));
String acceptHeader = request.getHeader(HttpHeaders.ACCEPT);
if (acceptHeader == null || acceptHeader.trim().isEmpty()) {
acceptHeader = "*/*";
}
List<String> knownTypes = Lists.newArrayList("text/plain", "application/xml");
// find the best matching mime type
String bestMediaTypeMatch = MIMEParse.bestMatch(knownTypes, acceptHeader);
if ("text/plain".equals(bestMediaTypeMatch)) {
return Response.ok(findRaw(data, rawCorpusNames, query), "text/plain").build();
} else {
List<Match> result = findXml(data, rawCorpusNames, query);
return Response.ok().type("application/xml").entity(new GenericEntity<MatchGroup>(new MatchGroup(result)) {
}).build();
}
}
use of annis.service.objects.MatchGroup in project ANNIS by korpling.
the class QueryServiceImpl method subgraph.
@GET
@Path("search/subgraph")
@Produces({ "application/xml", "application/xmi+xml", "application/xmi+binary", "application/graphml+xml" })
public SaltProject subgraph(@QueryParam("match") String matchRaw, @QueryParam("segmentation") String segmentation, @DefaultValue("0") @QueryParam("left") String leftRaw, @DefaultValue("0") @QueryParam("right") String rightRaw, @DefaultValue("all") @QueryParam("filter") String filterRaw) {
// some robustness stuff
requiredParameter(matchRaw, "match", "definition of the match");
MatchGroup matches = MatchGroup.parseString(matchRaw);
return basicSubgraph(matches, segmentation, leftRaw, rightRaw, filterRaw);
}
use of annis.service.objects.MatchGroup in project ANNIS by korpling.
the class GraphWithClauseGenerator method getMatchesWithClause.
@Override
protected List<String> getMatchesWithClause(QueryData queryData, List<QueryNode> alternative, String indent) {
TableAccessStrategy tas = createTableAccessStrategy();
List<AnnotateQueryData> extensions = queryData.getExtensions(AnnotateQueryData.class);
AnnotateQueryData annotateQueryData = extensions.isEmpty() ? new AnnotateQueryData(5, 5) : extensions.get(0);
List<MatchGroup> listOfSaltURIs = queryData.getExtensions(MatchGroup.class);
// only work with the first element
Validate.isTrue(!listOfSaltURIs.isEmpty());
List<String> subselects = new LinkedList<>();
String indent2 = indent + TABSTOP;
MatchGroup groupSet = listOfSaltURIs.get(0);
int matchNr = 1;
for (Match match : groupSet.getMatches()) {
List<URI> uriList = match.getSaltIDs();
int nodeNr = 1;
for (URI uri : uriList) {
String sub = indent2 + "(\n" + subselectForMatch(matchNr, nodeNr, uri, tas, annotateQueryData, queryData.getCorpusList(), indent2) + indent2 + ")";
subselects.add(0, sub);
nodeNr++;
}
matchNr++;
}
String result = indent + "matches AS\n" + indent + "(\n" + Joiner.on("\n" + indent2 + "UNION ALL\n").join(subselects) + "\n" + indent + ")";
return Lists.newArrayList(result);
}
Aggregations