Search in sources :

Example 1 with SaltProject

use of org.corpus_tools.salt.common.SaltProject in project ANNIS by korpling.

the class QueryDaoImpl method exportCorpus.

@Override
@Transactional(readOnly = true)
public void exportCorpus(String toplevelCorpus, File outputDirectory) {
    // check if the corpus really exists
    mapCorpusNameToId(toplevelCorpus);
    SaltProject corpusProject = SaltFactory.createSaltProject();
    SCorpusGraph corpusGraph = SaltFactory.createSCorpusGraph();
    corpusGraph.setSaltProject(corpusProject);
    SCorpus rootCorpus = corpusGraph.createCorpus(null, toplevelCorpus);
    // add all root metadata
    for (Annotation metaAnno : listCorpusAnnotations(toplevelCorpus)) {
        rootCorpus.createMetaAnnotation(metaAnno.getNamespace(), metaAnno.getName(), metaAnno.getValue());
    }
    File documentRootDir = new File(outputDirectory, toplevelCorpus);
    if (!outputDirectory.exists()) {
        if (!outputDirectory.mkdirs()) {
            log.warn("Could not create output directory \"{}\" for exporting the corpus", outputDirectory.getAbsolutePath());
        }
    }
    List<Annotation> docs = listDocuments(toplevelCorpus);
    int i = 1;
    for (Annotation docAnno : docs) {
        log.info("Loading document {} from database ({}/{})", docAnno.getName(), i, docs.size());
        SaltProject docProject = retrieveAnnotationGraph(toplevelCorpus, docAnno.getName(), null);
        if (docProject != null && docProject.getCorpusGraphs() != null && !docProject.getCorpusGraphs().isEmpty()) {
            List<Annotation> docMetaData = listCorpusAnnotations(toplevelCorpus, docAnno.getName(), true);
            SCorpusGraph docCorpusGraph = docProject.getCorpusGraphs().get(0);
            // TODO: we could re-use the actual corpus structure instead of just adding a flat list of documents
            if (docCorpusGraph.getDocuments() != null) {
                for (SDocument doc : docCorpusGraph.getDocuments()) {
                    log.info("Removing SFeatures from {} ({}/{})", docAnno.getName(), i, docs.size());
                    // remove all ANNIS specific features that require a special Java class
                    SDocumentGraph graph = doc.getDocumentGraph();
                    if (graph != null) {
                        if (graph.getNodes() != null) {
                            for (SNode n : graph.getNodes()) {
                                n.removeLabel(AnnisConstants.ANNIS_NS, AnnisConstants.FEAT_RELANNIS_NODE);
                            }
                        }
                        if (graph.getRelations() != null) {
                            for (SRelation e : graph.getRelations()) {
                                e.removeLabel(AnnisConstants.ANNIS_NS, AnnisConstants.FEAT_RELANNIS_EDGE);
                            }
                        }
                    }
                    log.info("Saving document {} ({}/{})", doc.getName(), i, docs.size());
                    SaltUtil.saveDocumentGraph(graph, URI.createFileURI(new File(documentRootDir, doc.getName() + "." + SaltUtil.FILE_ENDING_SALT_XML).getAbsolutePath()));
                    SDocument docCopy = corpusGraph.createDocument(rootCorpus, doc.getName());
                    log.info("Adding metadata to document {} ({}/{})", doc.getName(), i, docs.size());
                    for (Annotation metaAnno : docMetaData) {
                        docCopy.createMetaAnnotation(metaAnno.getNamespace(), metaAnno.getName(), metaAnno.getValue());
                    }
                }
            }
        }
        i++;
    }
    // end for each document
    // save the actual SaltProject
    log.info("Saving corpus structure");
    File projectFile = new File(outputDirectory, SaltUtil.FILE_SALT_PROJECT);
    SaltXML10Writer writer = new SaltXML10Writer(projectFile);
    writer.writeSaltProject(corpusProject);
}
Also used : SCorpus(org.corpus_tools.salt.common.SCorpus) SRelation(org.corpus_tools.salt.core.SRelation) SNode(org.corpus_tools.salt.core.SNode) SDocumentGraph(org.corpus_tools.salt.common.SDocumentGraph) SDocument(org.corpus_tools.salt.common.SDocument) SaltXML10Writer(org.corpus_tools.salt.util.internal.persistence.SaltXML10Writer) SaltProject(org.corpus_tools.salt.common.SaltProject) File(java.io.File) Annotation(annis.model.Annotation) SCorpusGraph(org.corpus_tools.salt.common.SCorpusGraph) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with SaltProject

use of org.corpus_tools.salt.common.SaltProject in project ANNIS by korpling.

the class QueryDaoImpl method retrieveAnnotationGraph.

@Override
@Transactional(readOnly = true)
public SaltProject retrieveAnnotationGraph(String toplevelCorpusName, String documentName, List<String> nodeAnnotationFilter) {
    long toplevelCorpusID = mapCorpusNameToId(toplevelCorpusName);
    SaltProject p = graphSqlGenerator.queryAnnotationGraph(getJdbcTemplate(), toplevelCorpusID, documentName, nodeAnnotationFilter);
    return p;
}
Also used : SaltProject(org.corpus_tools.salt.common.SaltProject) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with SaltProject

use of org.corpus_tools.salt.common.SaltProject in project ANNIS by korpling.

the class QueryServiceImpl method graph.

@GET
@Path("graph/{top}/{doc}")
@Produces({ "application/xml", "application/xmi+xml", "application/xmi+binary", "application/graphml+xml" })
@Override
public SaltProject graph(@PathParam("top") String toplevelCorpusName, @PathParam("doc") String documentName, @QueryParam("filternodeanno") String filternodeanno) {
    Subject user = SecurityUtils.getSubject();
    user.checkPermission("query:subgraph:" + toplevelCorpusName);
    List<String> nodeAnnotationFilter = null;
    if (filternodeanno != null) {
        nodeAnnotationFilter = Splitter.on(',').trimResults().omitEmptyStrings().splitToList(filternodeanno);
    }
    try {
        long start = new Date().getTime();
        SaltProject p = queryDao.retrieveAnnotationGraph(toplevelCorpusName, documentName, nodeAnnotationFilter);
        long end = new Date().getTime();
        logQuery("GRAPH", toplevelCorpusName, documentName, end - start);
        return p;
    } catch (Exception ex) {
        log.error("error when accessing graph " + toplevelCorpusName + "/" + documentName, ex);
        throw new WebApplicationException(ex, 500);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) SaltProject(org.corpus_tools.salt.common.SaltProject) Subject(org.apache.shiro.subject.Subject) Date(java.util.Date) WebApplicationException(javax.ws.rs.WebApplicationException) IOException(java.io.IOException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with SaltProject

use of org.corpus_tools.salt.common.SaltProject in project ANNIS by korpling.

the class AnnisRunner method doDoc.

public void doDoc(String docCall) {
    List<String> splitted = Splitter.on(' ').trimResults().omitEmptyStrings().splitToList(docCall);
    List<String> annoFilter = null;
    if (splitted.size() > 2) {
        annoFilter = Splitter.on(',').trimResults().omitEmptyStrings().splitToList(splitted.get(2));
    }
    Validate.isTrue(splitted.size() > 1, "must have two arguments (toplevel corpus name and document name");
    SaltProject p = queryDao.retrieveAnnotationGraph(splitted.get(0), splitted.get(1), annoFilter);
    System.out.println(printSaltAsXMI(p));
}
Also used : SaltProject(org.corpus_tools.salt.common.SaltProject)

Example 5 with SaltProject

use of org.corpus_tools.salt.common.SaltProject in project ANNIS by korpling.

the class BenchmarkTest method mapSaltAndSaveXMI_Pcc4282.

@Test
public void mapSaltAndSaveXMI_Pcc4282() throws IOException {
    assumeTrue(ridgesCorpusID.size() > 0);
    SaltProject p = annisDao.retrieveAnnotationGraph("pcc2", "4282", null);
    provider.writeTo(p, SaltProject.class, null, null, typeXMI, new StringKeyIgnoreCaseMultivaluedMap<>(), nullStream);
}
Also used : SaltProject(org.corpus_tools.salt.common.SaltProject) Test(org.junit.Test)

Aggregations

SaltProject (org.corpus_tools.salt.common.SaltProject)34 Test (org.junit.Test)11 Match (annis.service.objects.Match)8 WebResource (com.sun.jersey.api.client.WebResource)8 LinkedList (java.util.LinkedList)8 SDocumentGraph (org.corpus_tools.salt.common.SDocumentGraph)8 MatchGroup (annis.service.objects.MatchGroup)7 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)6 ArrayList (java.util.ArrayList)6 SDocument (org.corpus_tools.salt.common.SDocument)6 HashMap (java.util.HashMap)4 SCorpusGraph (org.corpus_tools.salt.common.SCorpusGraph)4 SNode (org.corpus_tools.salt.core.SNode)4 VisualizerInput (annis.libgui.visualizers.VisualizerInput)3 QueryData (annis.ql.parser.QueryData)3 SubgraphFilter (annis.service.objects.SubgraphFilter)3 AnnotateQueryData (annis.sqlgen.extensions.AnnotateQueryData)3 LimitOffsetQueryData (annis.sqlgen.extensions.LimitOffsetQueryData)3 IOException (java.io.IOException)3 AnnisCorpusAccessException (annis.exceptions.AnnisCorpusAccessException)2