示例#1
0
  /**
   * this method finds potential options based on the detected main subject; it is usually used when
   * none of the ontology-related annotations exist
   *
   * @param key
   * @return
   */
  public List<Vote> generateGenericVotes(
      SuggestionKey key, POC poc, boolean addNone, Integer max, List<SemanticConcept> toSkip) {
    Set<String> avoidThese = new HashSet<String>();
    if (toSkip != null)
      for (SemanticConcept concept : toSkip) {
        String uri = concept.getOntologyElement().getData().toString();
        avoidThese.add(uri);
      }
    String text = key.getText();
    List<Vote> votes = new ArrayList<Vote>();
    List<OntologyElement> elements;
    try {
      elements = findGenericOntologyElements(max);

      for (OntologyElement element : elements) {
        if (avoidThese.contains(element.getData().toString())) continue;
        element.setAnnotation(poc.getAnnotation());
        // run some similarity metric here and use some threshold...
        // if similarityScore>threshold then add this to the
        // clarificationOptions
        String pPropertyShortName = "";
        String suggestion = ((SerializableURI) element.getData()).toString();
        try {
          SerializableURI elementUri = new SerializableURI(suggestion, false);
          pPropertyShortName = elementUri.getResourceName();
        } catch (Exception e) {
          pPropertyShortName = suggestion;
        }
        String niceLabel = StringUtil.beautifyString(pPropertyShortName);
        Vote vote = new Vote();
        long id = incrementer.incrementAndGet();
        vote.setId(id);
        SemanticConcept candidateSemanticConcept = new SemanticConcept();
        candidateSemanticConcept.setOntologyElement(element);
        SemanticConcept clonedConcept = (SemanticConcept) candidateSemanticConcept.clone();
        vote.setCandidate(clonedConcept);
        double totalSimilarity = similarityCalculator.findSimilarity(text, niceLabel);
        vote.setVote(totalSimilarity);
        votes.add(vote);
        votes.addAll(addAdditionalVotes(element, poc, text, pPropertyShortName, false));
      }

      // here we add datatypeProperties with no domain etc.
      votes.addAll(
          generateVotesFromOntologyElements(findHangingElements(), avoidThese, poc, null, text));
    } catch (Exception e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }
    // add None element
    if (addNone) {
      Vote vote = VoteGenerator.generateNoneVote(incrementer.incrementAndGet());
      vote.getCandidate().getOntologyElement().setAnnotation(poc.getAnnotation());
      votes.add(vote);
    }
    return votes;
  }
示例#2
0
 /**
  * @param text
  * @param pPropertyShortNameOrUri
  * @param element
  * @param function
  * @return
  */
 public Vote generateVote(
     String text, String pPropertyShortNameOrUri, OntologyElement element, String function) {
   String niceLabel = StringUtil.beautifyString(pPropertyShortNameOrUri);
   Vote vote = new Vote();
   long id = incrementer.incrementAndGet();
   vote.setId(id);
   SemanticConcept candidateSemanticConcept = new SemanticConcept();
   candidateSemanticConcept.setOntologyElement(element);
   // element.setFunction(function);
   candidateSemanticConcept.setFunction(function);
   // SemanticConcept clonedElement =
   // (SemanticConcept)candidateSemanticConcept.clone();
   vote.setCandidate(candidateSemanticConcept);
   // vote.setCandidate(clonedElement);
   // give more weight to monge
   try {
     double totalSimilarity = similarityCalculator.findSimilarity(text, niceLabel);
     vote.setVote(totalSimilarity);
   } catch (Exception e) {
     e.printStackTrace();
   }
   return vote;
 }