Search in sources :

Example 6 with MatchGroup

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;
}
Also used : InputStreamReader(java.io.InputStreamReader) MatchGroup(annis.service.objects.MatchGroup)

Example 7 with MatchGroup

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());
        }
    }
}
Also used : ArrayCorpusPathExtractor(annis.sqlgen.ArrayCorpusPathExtractor) CorpusPathExtractor(annis.sqlgen.CorpusPathExtractor) ArrayList(java.util.ArrayList) SaltProject(org.corpus_tools.salt.common.SaltProject) PostgreSqlArraySolutionKey(annis.sqlgen.PostgreSqlArraySolutionKey) SaltAnnotateExtractor(annis.sqlgen.SaltAnnotateExtractor) Match(annis.service.objects.Match) AnnotationGraph(annis.model.AnnotationGraph) ArrayCorpusPathExtractor(annis.sqlgen.ArrayCorpusPathExtractor) MatchGroup(annis.service.objects.MatchGroup) AnnisNode(annis.model.AnnisNode) CsvResultSetProvider(annis.test.CsvResultSetProvider) Test(org.junit.Test)

Example 8 with MatchGroup

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();
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) QueryData(annis.ql.parser.QueryData) LimitOffsetQueryData(annis.sqlgen.extensions.LimitOffsetQueryData) AnnotateQueryData(annis.sqlgen.extensions.AnnotateQueryData) MatrixQueryData(annis.sqlgen.MatrixQueryData) Subject(org.apache.shiro.subject.Subject) Match(annis.service.objects.Match) OrderType(annis.service.objects.OrderType) GenericEntity(javax.ws.rs.core.GenericEntity) MatchGroup(annis.service.objects.MatchGroup) LimitOffsetQueryData(annis.sqlgen.extensions.LimitOffsetQueryData) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 9 with MatchGroup

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);
}
Also used : MatchGroup(annis.service.objects.MatchGroup) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 10 with MatchGroup

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);
}
Also used : MatchGroup(annis.service.objects.MatchGroup) AnnotateQueryData(annis.sqlgen.extensions.AnnotateQueryData) SqlConstraints.sqlString(annis.sqlgen.SqlConstraints.sqlString) URI(java.net.URI) LinkedList(java.util.LinkedList) Match(annis.service.objects.Match)

Aggregations

MatchGroup (annis.service.objects.MatchGroup)12 Match (annis.service.objects.Match)9 SaltProject (org.corpus_tools.salt.common.SaltProject)7 LinkedList (java.util.LinkedList)5 WebResource (com.sun.jersey.api.client.WebResource)4 AnnotateQueryData (annis.sqlgen.extensions.AnnotateQueryData)3 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)3 InputStreamReader (java.io.InputStreamReader)3 ArrayList (java.util.ArrayList)3 AnnisCorpusAccessException (annis.exceptions.AnnisCorpusAccessException)2 AnnisQLSemanticsException (annis.exceptions.AnnisQLSemanticsException)2 AnnisQLSyntaxException (annis.exceptions.AnnisQLSyntaxException)2 QueryData (annis.ql.parser.QueryData)2 AnnisAttribute (annis.service.objects.AnnisAttribute)2 SubgraphFilter (annis.service.objects.SubgraphFilter)2 LimitOffsetQueryData (annis.sqlgen.extensions.LimitOffsetQueryData)2 Stopwatch (com.google.common.base.Stopwatch)2 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2