use of annis.gui.objects.Query in project ANNIS by korpling.
the class QueryController method addHistoryEntry.
/**
* Adds a history entry to the history panel.
*
* @param q the entry, which is added.
*
* @see HistoryPanel
*/
public void addHistoryEntry(Query q) {
try {
Query queryCopy = q.clone();
// remove it first in order to let it appear on the beginning of the list
state.getHistory().removeItem(queryCopy);
state.getHistory().addItemAt(0, queryCopy);
searchView.getControlPanel().getQueryPanel().updateShortHistory();
} catch (CloneNotSupportedException ex) {
log.error("Can't clone the query", ex);
}
}
use of annis.gui.objects.Query in project ANNIS by korpling.
the class SearchView method evaluateFragment.
private void evaluateFragment(String fragment) {
// do nothing if not changed
if (fragment == null || fragment.isEmpty() || fragment.equals(lastEvaluatedFragment)) {
return;
}
Map<String, String> args = Helper.parseFragment(fragment);
if (args.containsKey("c")) {
String[] originalCorpusNames = args.get("c").split("\\s*,\\s*");
Set<String> corpora = getMappedCorpora(Arrays.asList(originalCorpusNames));
if (corpora.isEmpty()) {
if (Helper.getUser() == null && toolbar != null) {
// not logged in, show login window
boolean onlyCorpusSelected = args.containsKey("c") && args.size() == 1;
toolbar.showLoginWindow(!onlyCorpusSelected);
} else {
// already logged in or no login system available, just display a message
new Notification("Linked corpus does not exist", "<div><p>The corpus you wanted to access unfortunally does not (yet) exist" + " in ANNIS.</p>" + "<h2>possible reasons are:</h2>" + "<ul>" + "<li>that it has not been imported yet,</li>" + "<li>you don't have the access rights to see this corpus,</li>" + "<li>or the ANNIS service is not running.</li>" + "</ul>" + "<p>Please ask the responsible person of the site that contained " + "the link to import the corpus.</p></div>", Notification.Type.WARNING_MESSAGE, true).show(Page.getCurrent());
}
} else // end if corpus list returned from service is empty
{
if (args.containsKey("c") && args.size() == 1) {
// special case: we were called from outside and should only select,
// but not query, the selected corpora
ui.getQueryState().getSelectedCorpora().setValue(corpora);
} else if (args.get("cl") != null && args.get("cr") != null) {
// make sure the properties are not overwritten by the background process
getControlPanel().getSearchOptions().setUpdateStateFromConfig(false);
DisplayedResultQuery query = QueryGenerator.displayed().left(Integer.parseInt(args.get("cl"))).right(Integer.parseInt(args.get("cr"))).offset(Integer.parseInt(args.get("s"))).limit(Integer.parseInt(args.get("l"))).segmentation(args.get("seg")).baseText(args.get("bt")).query(args.get("q")).corpora(corpora).build();
if (query.getBaseText() == null && query.getSegmentation() != null) {
// if no explicit visible segmentation was given use the same as the context
query.setBaseText(query.getSegmentation());
}
if (query.getBaseText() != null && query.getBaseText().isEmpty()) {
// empty string means "null"
query.setBaseText(null);
}
String matchSelectionRaw = args.get("m");
if (matchSelectionRaw != null) {
for (String selectedMatchNr : Splitter.on(',').omitEmptyStrings().trimResults().split(matchSelectionRaw)) {
try {
long nr = Long.parseLong(selectedMatchNr);
query.getSelectedMatches().add(nr);
} catch (NumberFormatException ex) {
log.warn("Invalid long provided as selected match", ex);
}
}
}
if (args.get("o") != null) {
try {
query.setOrder(OrderType.valueOf(args.get("o").toLowerCase()));
} catch (IllegalArgumentException ex) {
log.warn("Could not parse query fragment argument for order", ex);
}
}
// full query with given context
ui.getQueryController().setQuery(query);
ui.getQueryController().executeSearch(true, false);
} else if (args.get("q") != null) {
// use default context
ui.getQueryController().setQuery(new Query(args.get("q"), corpora));
ui.getQueryController().executeSearch(true, true);
}
getControlPanel().getCorpusList().scrollToSelectedCorpus();
}
// end if corpus list from server was non-empty
}
// end if there is a corpus definition
}
use of annis.gui.objects.Query in project ANNIS by korpling.
the class SearchView method evaluateCitation.
public void evaluateCitation(String relativeUri) {
Matcher m = citationPattern.matcher(relativeUri);
if (m.matches()) {
// AQL
String aql = "";
if (m.group(1) != null) {
aql = m.group(1);
}
// CIDS
Set<String> selectedCorpora = new HashSet<>();
if (m.group(2) != null) {
String[] cids = m.group(2).split(",");
selectedCorpora.addAll(Arrays.asList(cids));
}
// filter by actually avaible user corpora in order not to get any exception later
WebResource res = Helper.getAnnisWebResource();
List<AnnisCorpus> userCorpora = res.path("query").path("corpora").get(new AnnisCorpusListType());
LinkedList<String> userCorporaStrings = new LinkedList<>();
for (AnnisCorpus c : userCorpora) {
userCorporaStrings.add(c.getName());
}
selectedCorpora.retainAll(userCorporaStrings);
// CLEFT and CRIGHT
if (m.group(4) != null && m.group(6) != null) {
int cleft = 0;
int cright = 0;
try {
cleft = Integer.parseInt(m.group(4));
cright = Integer.parseInt(m.group(6));
} catch (NumberFormatException ex) {
log.error("could not parse context value", ex);
}
ui.getQueryController().setQuery(new PagedResultQuery(cleft, cright, 0, 10, null, aql, selectedCorpora));
} else {
ui.getQueryController().setQuery(new Query(aql, selectedCorpora));
}
// remove all currently openend sub-windows
Set<Window> all = new HashSet<>(ui.getWindows());
for (Window w : all) {
ui.removeWindow(w);
}
} else {
Notification.show("Invalid citation", Notification.Type.WARNING_MESSAGE);
}
}
use of annis.gui.objects.Query in project ANNIS by korpling.
the class CitationLinkGenerator method generateCell.
@Override
public Object generateCell(Table source, Object itemId, Object columnId) {
Button btLink = new Button();
btLink.addStyleName(ValoTheme.BUTTON_BORDERLESS);
btLink.setIcon(FontAwesome.SHARE_ALT);
btLink.setDescription("Share query reference link");
btLink.addClickListener(this);
if (itemId instanceof DisplayedResultQuery) {
btLink.addClickListener(new LinkClickListener((DisplayedResultQuery) itemId));
} else if (itemId instanceof Query) {
final CitationProvider citationProvider = new CitationProviderForQuery((Query) itemId);
btLink.addClickListener(new LinkClickListener(citationProvider));
} else if (itemId instanceof CitationProvider) {
final CitationProvider citationProvider = (CitationProvider) itemId;
btLink.addClickListener(new LinkClickListener(citationProvider));
}
return btLink;
}
use of annis.gui.objects.Query in project ANNIS by korpling.
the class QueryPanel method updateShortHistory.
public void updateShortHistory() {
historyContainer.removeAllItems();
int counter = 0;
for (Query q : state.getHistory().getItemIds()) {
if (counter >= MAX_HISTORY_MENU_ITEMS) {
break;
} else {
historyContainer.addBean(q);
}
counter++;
}
}
Aggregations