Search in sources :

Example 11 with SDocument

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

the class ResultViewPanel method createPanels.

private List<SingleResultPanel> createPanels(SaltProject p, int localMatchIndex, long globalOffset) {
    List<SingleResultPanel> result = new LinkedList<>();
    int i = 0;
    for (SCorpusGraph corpusGraph : p.getCorpusGraphs()) {
        SDocument doc = corpusGraph.getDocuments().get(0);
        Match m = new Match();
        if (allMatches != null && localMatchIndex >= 0 && localMatchIndex < allMatches.size()) {
            m = allMatches.get(localMatchIndex);
        }
        SingleResultPanel panel = new SingleResultPanel(doc, m, i + globalOffset, new ResolverProviderImpl(cacheResolver), ps, sui, getVisibleTokenAnnos(), segmentationName, controller, instanceConfig, initialQuery);
        i++;
        panel.setWidth("100%");
        panel.setHeight("-1px");
        result.add(panel);
    }
    return result;
}
Also used : ResolverProviderImpl(annis.libgui.ResolverProviderImpl) SDocument(org.corpus_tools.salt.common.SDocument) LinkedList(java.util.LinkedList) SCorpusGraph(org.corpus_tools.salt.common.SCorpusGraph) Match(annis.service.objects.Match)

Example 12 with SDocument

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

the class CommonHelper method getTokenAnnotationLevelSet.

public static Set<String> getTokenAnnotationLevelSet(SaltProject p) {
    Set<String> result = new TreeSet<String>();
    for (SCorpusGraph corpusGraphs : p.getCorpusGraphs()) {
        for (SDocument doc : corpusGraphs.getDocuments()) {
            SDocumentGraph g = doc.getDocumentGraph();
            result.addAll(getTokenAnnotationLevelSet(g));
        }
    }
    return result;
}
Also used : TreeSet(java.util.TreeSet) SDocumentGraph(org.corpus_tools.salt.common.SDocumentGraph) SDocument(org.corpus_tools.salt.common.SDocument) SCorpusGraph(org.corpus_tools.salt.common.SCorpusGraph)

Example 13 with SDocument

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

the class GraphMLProvider method writeTo.

@Override
public void writeTo(SaltProject t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
    // collect document graphs from the salt project
    List<SDocument> docs = new LinkedList<>();
    List<SCorpusGraph> corpusGraphs = t.getCorpusGraphs();
    if (corpusGraphs != null) {
        for (SCorpusGraph c : corpusGraphs) {
            if (c.getDocuments() != null) {
                docs.addAll(c.getDocuments());
            }
        }
    }
    GraphMLWriter.writeDocuments(entityStream, docs);
}
Also used : SDocument(org.corpus_tools.salt.common.SDocument) LinkedList(java.util.LinkedList) SCorpusGraph(org.corpus_tools.salt.common.SCorpusGraph)

Example 14 with SDocument

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

the class SaltProjectProvider method writeTo.

@Override
public void writeTo(SaltProject project, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
    SaltXML10Writer writer = new SaltXML10Writer();
    try {
        XMLStreamWriter xml = outFactory.createXMLStreamWriter(entityStream, "UTF-8");
        xml.writeStartDocument("1.1");
        xml.writeCharacters("\n");
        long startTime = System.currentTimeMillis();
        // output XMI root element
        writer.writeXMIRootElement(xml);
        for (SCorpusGraph corpusGraph : project.getCorpusGraphs()) {
            for (SDocument doc : corpusGraph.getDocuments()) {
                // make sure that any ANNIS feature on the document is copied to the document graph
                SDocumentGraph docGraph = doc.getDocumentGraph();
                for (SFeature feat : doc.getFeatures()) {
                    if (AnnisConstants.ANNIS_NS.equals(feat.getNamespace())) {
                        SFeature newFeat = SaltFactory.createSFeature();
                        feat.copy(newFeat);
                        docGraph.addFeature(newFeat);
                    }
                }
                writer.writeObjects(xml, docGraph);
            }
        }
        xml.writeEndDocument();
        long endTime = System.currentTimeMillis();
        log.debug("Saving XMI (" + mediaType.toString() + ") needed {} ms", endTime - startTime);
    } catch (XMLStreamException ex) {
        log.error("exception when serializing SDocumentGraph", ex);
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) SDocumentGraph(org.corpus_tools.salt.common.SDocumentGraph) SaltXML10Writer(org.corpus_tools.salt.util.internal.persistence.SaltXML10Writer) SDocument(org.corpus_tools.salt.common.SDocument) SCorpusGraph(org.corpus_tools.salt.common.SCorpusGraph) SFeature(org.corpus_tools.salt.core.SFeature)

Example 15 with SDocument

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

the class SaltProjectProvider method readFrom.

@Override
public SaltProject readFrom(Class<SaltProject> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
    SaltProject result = SaltFactory.createSaltProject();
    SAXParser parser;
    XMLReader xmlReader;
    SAXParserFactory factory = SAXParserFactory.newInstance();
    MixedContentHandler handler = new MixedContentHandler();
    try {
        parser = factory.newSAXParser();
        xmlReader = parser.getXMLReader();
        xmlReader.setContentHandler(handler);
        InputSource source = new InputSource(entityStream);
        source.setEncoding("UTF-8");
        xmlReader.parse(source);
        for (SDocumentGraph g : handler.getDocGraphs()) {
            // create a separate corpus graph for each document
            SCorpusGraph corpusGraph = SaltFactory.createSCorpusGraph();
            SCorpus parentCorpus = null;
            SDocument doc = null;
            List<SNode> nodes = g.getNodes();
            Iterator<String> it;
            if (nodes != null && !nodes.isEmpty()) {
                // the path of each node ID is always the document/corpus path
                it = nodes.get(0).getPath().segmentsList().iterator();
            } else {
                // Old salt versions had a separate ID for the document graph
                // which was the document name with the suffix "_graph".
                // Thus this method of getting the corpus path is only the fallback.
                it = g.getPath().segmentsList().iterator();
            }
            while (it.hasNext()) {
                String name = it.next();
                if (it.hasNext()) {
                    // this is a sub-corpus
                    parentCorpus = corpusGraph.createCorpus(parentCorpus, name);
                } else {
                    // no more path elements left, must be a document
                    doc = corpusGraph.createDocument(parentCorpus, name);
                    break;
                }
            }
            if (doc != null) {
                result.addCorpusGraph(corpusGraph);
                doc.setDocumentGraph(g);
            }
        }
    } catch (ParserConfigurationException | SAXException ex) {
        log.error("Error when parsing XMI", ex);
    }
    return result;
}
Also used : InputSource(org.xml.sax.InputSource) SNode(org.corpus_tools.salt.core.SNode) SDocument(org.corpus_tools.salt.common.SDocument) SaltProject(org.corpus_tools.salt.common.SaltProject) SCorpusGraph(org.corpus_tools.salt.common.SCorpusGraph) SAXException(org.xml.sax.SAXException) SCorpus(org.corpus_tools.salt.common.SCorpus) SDocumentGraph(org.corpus_tools.salt.common.SDocumentGraph) SAXParser(javax.xml.parsers.SAXParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) XMLReader(org.xml.sax.XMLReader) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Aggregations

SDocument (org.corpus_tools.salt.common.SDocument)15 SCorpusGraph (org.corpus_tools.salt.common.SCorpusGraph)12 SDocumentGraph (org.corpus_tools.salt.common.SDocumentGraph)8 SaltProject (org.corpus_tools.salt.common.SaltProject)6 SNode (org.corpus_tools.salt.core.SNode)6 LinkedList (java.util.LinkedList)4 SToken (org.corpus_tools.salt.common.SToken)4 VisualizerInput (annis.libgui.visualizers.VisualizerInput)3 Match (annis.service.objects.Match)3 HashMap (java.util.HashMap)3 SCorpus (org.corpus_tools.salt.common.SCorpus)3 WebResource (com.sun.jersey.api.client.WebResource)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Random (java.util.Random)2 TreeSet (java.util.TreeSet)2 SRelation (org.corpus_tools.salt.core.SRelation)2 AnnisUser (annis.libgui.AnnisUser)1 InstanceConfig (annis.libgui.InstanceConfig)1 LoginDataLostException (annis.libgui.LoginDataLostException)1