コード例 #1
0
  @Test
  public void shouldCumulateHits() throws Exception {
    IndexTestDouble index =
        new IndexTestDouble().resultFor("2012", "predicate", 1).resultFor("2010", "predicate", 1);

    AnnotationAlgorithm majorityHitWeighted =
        new WeightedFrequencyCoverageAndSpecificity(
            emptyTypes(), index, new OnlyValue(new IndexFields("dbpedia")), new Constant());

    List<CandidateProperty> results =
        majorityHitWeighted.annotate(
            new ContextualizedValues("any", new String[] {"2012", "2010"}));

    assertThat(results.get(0).score(), equalTo(0.5142717790222688));
  }
コード例 #2
0
  @Test
  public void shouldNotOrderWithoutConsideringTheWeightOfPredicates() throws Exception {
    Directory directory = buildIndex();

    ContextualizedEvidence index =
        new ContextualizedEvidence(directory, new ConstantSimilarity(), new IndexFields("dbpedia"));

    AnnotationAlgorithm majorityHitWeighted =
        new WeightedFrequencyCoverageAndSpecificity(
            emptyTypes(), index, new OnlyValue(new IndexFields("dbpedia")), new Constant());

    List<CandidateProperty> results =
        majorityHitWeighted.annotate(new ContextualizedValues("context", new String[] {"value"}));

    assertThat(results.get(0).score(), equalTo(results.get(1).score()));
  }
コード例 #3
0
  @Test
  public void shouldConsiderCoverageOfThePredicatesOverValues() throws Exception {
    IndexTestDouble index =
        new IndexTestDouble()
            .resultFor("2012", "lowCoveragePredicate", 2)
            .resultFor("2010", "highCoveragePredicate", 1)
            .resultFor("2012", "highCoveragePredicate", 1);

    AnnotationAlgorithm algorithm =
        new WeightedFrequencyCoverageAndSpecificity(
            emptyTypes(), index, new OnlyValue(new IndexFields("dbpedia")), new Constant());

    List<CandidateProperty> results =
        algorithm.annotate(new ContextualizedValues("context", new String[] {"2012", "2010"}));

    assertThat(results.get(0).label(), equalTo("highCoveragePredicate"));
  }
コード例 #4
0
  @Test
  public void shouldOrderConsideringCompleteContext() throws Exception {
    Directory directory = buildIndex();
    IndexFields fields = new IndexFields("dbpedia");

    ContextualizedEvidence index =
        new ContextualizedEvidence(directory, new ConstantSimilarity(), fields);

    AnnotationAlgorithm majorityHitWeighted =
        new WeightedFrequencyCoverageAndSpecificity(
            emptyTypes(),
            index,
            new FullyContextualizedValue(fields),
            new PropertyContextSpecificity(index, new IndexFields("dbpedia")));

    List<CandidateProperty> results =
        majorityHitWeighted.annotate(new ContextualizedValues("context", new String[] {"value"}));

    assertThat(results.get(0).score(), greaterThan(results.get(1).score()));
  }