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