Search in sources :

Example 1 with MetricResponse

use of edu.illinois.cs.cogcomp.sim.MetricResponse in project cogcomp-nlp by CogComp.

the class WordComparator method compare.

@Override
public EntailmentResult compare(String specific_, String general_) {
    String genTok = StringCleanup.normalizeToLatin1(general_);
    String specTok = StringCleanup.normalizeToLatin1(specific_);
    double score = 0.0;
    String reason = "default reason";
    String source = WordComparator.class.getSimpleName();
    boolean isEntailed = false;
    boolean isPositivePolarity = true;
    if (specTok.equalsIgnoreCase(genTok)) {
        score = 1.0;
        reason = "Identity";
    } else {
        MetricResponse result = wordSim.compare(specific_, general_);
        score = result.score;
        reason = result.reason;
        isEntailed = (Math.abs(score) > entailmentThreshold);
        isPositivePolarity = (score >= 0);
        if (computeSimpleScore) {
            if (isEntailed) {
                score = 1.0;
            }
        }
    }
    return new EntailmentResult(source, (float) score, reason, isEntailed, isPositivePolarity, defaultUpwardMonotone, null);
}
Also used : MetricResponse(edu.illinois.cs.cogcomp.sim.MetricResponse) EntailmentResult(edu.illinois.cs.cogcomp.mrcs.dataStructures.EntailmentResult)

Example 2 with MetricResponse

use of edu.illinois.cs.cogcomp.sim.MetricResponse in project cogcomp-nlp by CogComp.

the class NEComparator method compare.

@Override
public EntailmentResult compare(String specific_, String general_) throws Exception {
    String genTok = StringCleanup.normalizeToLatin1(general_);
    String specTok = StringCleanup.normalizeToLatin1(specific_);
    double score = 0.0;
    String reason = "default reason";
    String source = WordComparator.class.getSimpleName();
    boolean isEntailed = false;
    boolean isPositivePolarity = true;
    if (specTok.equalsIgnoreCase(genTok)) {
        score = 1.0;
        reason = "Identity";
    } else {
        MetricResponse result = NEComparator.compare(specific_, general_);
        score = result.score;
        reason = result.reason;
        isEntailed = (Math.abs(score) > 0.5);
        isPositivePolarity = (score >= 0);
    }
    return new EntailmentResult(source, (float) score, reason, isEntailed, isPositivePolarity, true, null);
}
Also used : MetricResponse(edu.illinois.cs.cogcomp.sim.MetricResponse) EntailmentResult(edu.illinois.cs.cogcomp.mrcs.dataStructures.EntailmentResult)

Example 3 with MetricResponse

use of edu.illinois.cs.cogcomp.sim.MetricResponse in project cogcomp-nlp by CogComp.

the class EntityComparisonTest method testEntityComparison.

@Test
public void testEntityComparison() {
    Metric ec = new NESim();
    String hitchA = "Bill C. Hitchcock";
    String hitchB = "William Hitchcock";
    String hitchC = "Mrs. Hitchcock";
    String hitchD = "Arthur Hitchcock";
    String hitchE = "Bill F. Hitchcock";
    MetricResponse result = ec.compare(hitchA, hitchB);
    assertEquals(result.score, 1.0, 0.01);
    /**
     * this test FAILS: no gender test
     */
    result = ec.compare(hitchB, hitchC);
    // assertTrue(Double.parseDouble(result.get(EntityComparison.SCORE)) <
    // 0.5);
    result = ec.compare(hitchB, hitchD);
    assertTrue(result.score < 0.6);
    result = ec.compare(hitchA, hitchE);
// Another test that fails. Critical local difference.
// assertTrue( Double.parseDouble( result.get( EntityComparison.SCORE )
// ) < 0.6 );
}
Also used : MetricResponse(edu.illinois.cs.cogcomp.sim.MetricResponse) Metric(edu.illinois.cs.cogcomp.sim.Metric) NESim(edu.illinois.cs.cogcomp.sim.NESim) Test(org.junit.Test)

Example 4 with MetricResponse

use of edu.illinois.cs.cogcomp.sim.MetricResponse in project cogcomp-nlp by CogComp.

the class WordSimTest method testParagram.

@Test
public void testParagram() throws Exception {
    WordSim ws = new WordSim(rm_, "paragram");
    MetricResponse m1 = ws.compare("word", "sentence", "paragram");
    MetricResponse m2 = ws.compare("word", "wife", "paragram");
    assertTrue(m1.score > m2.score);
}
Also used : WordSim(edu.illinois.cs.cogcomp.sim.WordSim) MetricResponse(edu.illinois.cs.cogcomp.sim.MetricResponse) Test(org.junit.Test)

Example 5 with MetricResponse

use of edu.illinois.cs.cogcomp.sim.MetricResponse in project cogcomp-nlp by CogComp.

the class WordSimTest method testWordNet.

@Test
public void testWordNet() {
    WordSim ws = new WordSim(rm_, "wordnet");
    MetricResponse m1 = ws.compare("word", "sentence", "wordnet");
    MetricResponse m2 = ws.compare("word", "wife", "wordnet");
    assertTrue(m1.score > m2.score);
}
Also used : WordSim(edu.illinois.cs.cogcomp.sim.WordSim) MetricResponse(edu.illinois.cs.cogcomp.sim.MetricResponse) Test(org.junit.Test)

Aggregations

MetricResponse (edu.illinois.cs.cogcomp.sim.MetricResponse)5 Test (org.junit.Test)3 EntailmentResult (edu.illinois.cs.cogcomp.mrcs.dataStructures.EntailmentResult)2 WordSim (edu.illinois.cs.cogcomp.sim.WordSim)2 Metric (edu.illinois.cs.cogcomp.sim.Metric)1 NESim (edu.illinois.cs.cogcomp.sim.NESim)1