use of org.corpus_tools.salt.common.SaltProject in project ANNIS by korpling.
the class ResultViewPanel method addQueryResult.
private void addQueryResult(PagedResultQuery q, List<SaltProject> subgraphList) {
if (q == null) {
return;
}
List<SingleResultPanel> newPanels = new LinkedList<>();
try {
if (subgraphList == null || subgraphList.isEmpty()) {
Notification.show("Could not get subgraphs", Notification.Type.TRAY_NOTIFICATION);
} else {
for (SaltProject p : subgraphList) {
updateVariables(p);
newPanels = createPanels(p, currentResults, q.getOffset() + currentResults);
currentResults += newPanels.size();
String strResults = numberOfResults > 1 ? "results" : "result";
sui.getSearchView().getControlPanel().getQueryPanel().setStatus(sui.getSearchView().getControlPanel().getQueryPanel().getLastPublicStatus(), " (showing " + currentResults + "/" + numberOfResults + " " + strResults + ")");
if (currentResults == numberOfResults) {
resetQueryResultQueue();
}
for (SingleResultPanel panel : newPanels) {
resultPanelList.add(panel);
resultLayout.addComponent(panel);
panel.setSegmentationLayer(sui.getQueryState().getVisibleBaseText().getValue());
}
}
if (currentResults == numberOfResults) {
showFinishedSubgraphSearch();
if (!initialQuery.getSelectedMatches().isEmpty()) {
// scroll to the first selected match
JavaScript.eval("$(\".v-panel-content-result-view-panel\").animate({scrollTop: $(\".selected-match\").offset().top - $(\".result-view-panel\").offset().top}, 1000);");
}
}
if (projectQueue != null && !newPanels.isEmpty() && currentResults < numberOfResults) {
log.debug("adding callback for result " + currentResults);
// add a callback so we can load the next single result
OnLoadCallbackExtension ext = new OnLoadCallbackExtension(this, 250);
ext.extend(newPanels.get(newPanels.size() - 1));
}
}
} catch (Throwable ex) {
log.error(null, ex);
}
}
use of org.corpus_tools.salt.common.SaltProject in project ANNIS by korpling.
the class ResultViewPanel method onCompononentLoaded.
@Override
public boolean onCompononentLoaded(AbstractClientConnector source) {
if (source != null) {
if (projectQueue != null && currentQuery != null) {
LinkedList<SaltProject> subgraphs = new LinkedList<>();
SaltProject p;
while ((p = projectQueue.poll()) != null) {
log.debug("Polling queue for SaltProject graph");
subgraphs.add(p);
}
if (subgraphs.isEmpty()) {
log.debug("no SaltProject graph in queue");
return false;
}
log.debug("taken {} SaltProject graph(s) from queue", subgraphs.size());
addQueryResult(currentQuery, subgraphs);
return true;
}
}
return true;
}
use of org.corpus_tools.salt.common.SaltProject in project ANNIS by korpling.
the class VisualizerPanel method getDocument.
private SaltProject getDocument(String toplevelCorpusName, String documentName, List<String> nodeAnnoFilter) {
SaltProject txt = null;
try {
toplevelCorpusName = urlPathEscape.escape(toplevelCorpusName);
documentName = urlPathEscape.escape(documentName);
WebResource res = Helper.getAnnisWebResource().path("query").path("graph").path(toplevelCorpusName).path(documentName);
if (nodeAnnoFilter != null) {
res = res.queryParam("filternodeanno", Joiner.on(",").join(nodeAnnoFilter));
}
txt = res.get(SaltProject.class);
} catch (ClientHandlerException | UniformInterfaceException e) {
log.error("General remote service exception", e);
}
return txt;
}
use of org.corpus_tools.salt.common.SaltProject 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;
}
Aggregations