public void setExamples(List<String> posExamples, List<String> negExamples) { try { exampleFinder.setExamples(posExamples, negExamples); } catch (Exception e) { logger.error("Error while setting positive and negative examples.", e); } }
public Example getSimilarExample(List<String> posExamples, List<String> negExamples) throws AutoSPARQLException { if (negExamples.isEmpty()) { // negExamples = getIntermediateNegativeExamples(posExamples); } Example example; try { example = exampleFinder.findSimilarExample(posExamples, negExamples); examplesCache.put(example.getURI(), example); return example; } catch (EmptyLGGException e) { logger.error(e); throw new AutoSPARQLException( "You selected some positive examples, which seem to have nothing in " + "common with respect to the target concept."); } catch (NegativeTreeCoverageExecption e) { logger.error(e); throw new AutoSPARQLException( "The query of the currently selected positive examples covers the negative example \"" + e.getCoveredNegativeExample() + "\"."); } catch (TimeOutException e) { logger.error(e); throw new AutoSPARQLException( "The computation of a new suggestion needs too much time. Please add manually more positive examples."); } catch (Exception e) { logger.error("Error while computing similar example.", e); throw new AutoSPARQLException("An error occured while generating a new suggestion."); } }
public void saveSPARQLQuery(Store store) throws AutoSPARQLException { List<Example> posExamples = new ArrayList<Example>(); for (String uri : exampleFinder.getPositiveExamples()) { posExamples.add(examplesCache.get(uri)); } List<Example> negExamples = new ArrayList<Example>(); for (String uri : exampleFinder.getNegativeExamples()) { negExamples.add(examplesCache.get(uri)); } store.saveSPARQLQuery( question, exampleFinder.getCurrentQuery(), endpoint.getLabel(), posExamples, negExamples, exampleFinder.getLastSuggestedExample()); }
public String getCurrentQuery() throws AutoSPARQLException { try { // return exampleFinder.getCurrentQueryHTML(); return exampleFinder.getCurrentQuery(); } catch (Exception e) { logger.error("Error while getting current query.", e); throw new AutoSPARQLException(e); } }
public PagingLoadResult<Example> getCurrentQueryResult(PagingLoadConfig config) throws SPARQLQueryException { logger.debug("Retrieving results for current query."); List<Example> queryResult = new ArrayList<Example>(); String currentQuery = exampleFinder.getCurrentQuery(); logger.debug("Current query:\n"); logger.debug(currentQuery); int limit = config.getLimit(); int offset = config.getOffset(); int totalLength = 10; try { ResultSetRewindable rs = SparqlQuery.convertJSONtoResultSet( selectCache.executeSelectQuery(endpoint, getCountQuery(currentQuery))); totalLength = rs.next().getLiteral(rs.getResultVars().get(0)).getInt(); } catch (Exception e) { e.printStackTrace(); } try { ResultSetRewindable rs = SparqlQuery.convertJSONtoResultSet( selectCache.executeSelectQuery( endpoint, modifyQuery(currentQuery + " LIMIT " + limit + " OFFSET " + offset))); String uri; String label = ""; String imageURL = ""; String comment = ""; QuerySolution qs; while (rs.hasNext()) { qs = rs.next(); uri = qs.getResource("x0").getURI(); label = qs.getLiteral("label").getLexicalForm(); queryResult.add(new Example(uri, label, imageURL, comment)); } } catch (Exception e) { logger.error("Error while getting result for query \n" + currentQuery, e); } PagingLoadResult<Example> result = new BasePagingLoadResult<Example>(queryResult); result.setOffset(offset); result.setTotalLength(totalLength); return result; }
public void setQuestion(String question) { this.question = question; exampleFinder.setQuestion(question); }