Skip to content

Commit

Permalink
Merge branch 'tmp/v1.2.0' (early part) into release
Browse files Browse the repository at this point in the history
  • Loading branch information
Roberto Zanoli committed Dec 22, 2014
2 parents 5ccf895 + 99513d2 commit 6c97b1d
Show file tree
Hide file tree
Showing 1,001 changed files with 22,209 additions and 500 deletions.
6 changes: 3 additions & 3 deletions alignmentedas/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>eu.excitementproject</groupId>
<artifactId>eop</artifactId>
<version>1.1.4</version>
<version>1.2.0</version>
</parent>
<artifactId>alignmentedas</artifactId>
<name>alignmentedas</name>
Expand All @@ -17,12 +17,12 @@
<dependency>
<groupId>eu.excitementproject</groupId>
<artifactId>core</artifactId>
<version>1.1.4</version>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>eu.excitementproject</groupId>
<artifactId>lap</artifactId>
<version>1.1.4</version>
<version>1.2.0</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
import eu.excitementproject.eop.alignmentedas.p1eda.instances.SimpleWordCoverageDE;
import eu.excitementproject.eop.alignmentedas.p1eda.instances.SimpleWordCoverageEN;
import eu.excitementproject.eop.alignmentedas.p1eda.instances.SimpleWordCoverageIT;
import eu.excitementproject.eop.alignmentedas.p1eda.sandbox.WNVOMT;
import eu.excitementproject.eop.alignmentedas.p1eda.sandbox.FNR_EN;
import eu.excitementproject.eop.alignmentedas.p1eda.sandbox.WithVO;
import eu.excitementproject.eop.alignmentedas.p1eda.sandbox.WithoutVO;
import eu.excitementproject.eop.alignmentedas.p1eda.sandbox.DEWithoutDerivBase;
import eu.excitementproject.eop.alignmentedas.p1eda.sandbox.DEWithDerivBase;
import eu.excitementproject.eop.common.EDAException;
import eu.excitementproject.eop.lap.LAPException;
import eu.excitementproject.eop.lap.dkpro.TreeTaggerDE;
Expand All @@ -28,6 +30,8 @@
/**
* A simple (EOP)-RTE XML data runner for P1EDA configurations
*
* (Note that, basic LAP for P1EDA configurations are TreeTagger using pipelines.
* Thus, you need to have TreeTagger dependencies in lap/POM.xml
*/
@SuppressWarnings("unused")
public class P1EdaRTERunner
Expand All @@ -41,12 +45,13 @@ public static void main( String[] args )
{
// Prepare LAP and EDA (here, both for English) and eval on RTE3 (again, EN)
LAP_ImplBase lapEN = new TreeTaggerEN();
P1EDATemplate p1edaEN = new SimpleWordCoverageEN(); // Put your (configured, instance) P1EDA here...
P1EDATemplate p1edaEN = new SimpleWordCoverageEN("../core/src/main/resources/ontologies/EnglishWordNet-dict","../core/src/main/resources/VerbOcean/verbocean.unrefined.2004-05-20.txt"); // Put your (configured, instance) P1EDA here...
evaluateOnRTE3EN(lapEN, p1edaEN, false); // set final argument true, if lap has not been changed from last call. (to reuse saved XMI files)

// use evaluateOnRTE3DE for German
// LAP_ImplBase lapDE = new TreeTaggerDE();
// P1EDATemplate p1edaDE = new SimpleWordCoverageDE();
//// P1EDATemplate p1edaDE = new DEWithoutDerivBase();
// evaluateOnRTE3DE(lapDE, p1edaDE, false);

// use evaluateOnRTE3IT for Italian
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public TEDecisionWithAlignment process(JCas eopJCas) throws EDAException

// Finally, return a TEDecision object with CAS (which holds alignments)
logger.debug("TEDecision object generated and being returned: " + result.getLabel() + ", " + result.getConfidence());
return new TEDecisionWithAlignment(result.getLabel(), result.getConfidence(), pairID, eopJCas);
return new TEDecisionWithAlignment(result.getLabel(), result.getConfidence(), pairID, eopJCas, featureValues);
}

public void initialize(CommonConfig conf) throws EDAException
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
*
* WARNING: a work in progress (basically, P1EDA + confidence model + its training)
* DO NOT USE this code.
*/
package eu.excitementproject.eop.alignmentedas.p1eda;

Expand Down Expand Up @@ -86,7 +87,7 @@
* @author Tae-Gil Noh
*
*/
public abstract class P1EDAFullTemplate implements EDABasic<TEDecisionWithAlignment> {
public abstract class P2EDATemplate implements EDABasic<TEDecisionWithAlignment> {

/**
* The default, no argument constructor for this abstract class. Does nothing
Expand All @@ -100,7 +101,7 @@ public abstract class P1EDAFullTemplate implements EDABasic<TEDecisionWithAlignm
* For example, see SimpleWordCoverageP1EDA.
*
*/
public P1EDAFullTemplate() throws EDAException
public P2EDATemplate() throws EDAException
{
this(null);
}
Expand All @@ -122,7 +123,7 @@ public P1EDAFullTemplate() throws EDAException
* @param evaluateAlignmentParameter
* @throws EDAException
*/
public P1EDAFullTemplate(Vector<ParameterValue> evaluateAlignmentParameter) throws EDAException
public P2EDATemplate(Vector<ParameterValue> evaluateAlignmentParameter) throws EDAException
{
this.logger = Logger.getLogger(getClass());
this.classifier = prepareClassifier();
Expand Down Expand Up @@ -169,7 +170,7 @@ public TEDecisionWithAlignment process(JCas eopJCas) throws EDAException

// Finally, return a TEDecision object with CAS (which holds alignments)
logger.debug("TEDecision object generated and being returned: " + result.getLabel() + ", " + result.getConfidence());
return new TEDecisionWithAlignment(result.getLabel(), result.getConfidence(), pairID, eopJCas);
return new TEDecisionWithAlignment(result.getLabel(), result.getConfidence(), pairID, eopJCas, null);
}

public void initialize(CommonConfig conf) throws EDAException
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package eu.excitementproject.eop.alignmentedas.p1eda;

import org.apache.uima.jcas.JCas;
import java.util.Vector;

import org.apache.uima.jcas.JCas;
import eu.excitementproject.eop.alignmentedas.p1eda.subs.FeatureValue;
import eu.excitementproject.eop.common.DecisionLabel;
import eu.excitementproject.eop.common.TEDecision;

Expand All @@ -20,12 +22,13 @@
*/
public class TEDecisionWithAlignment implements TEDecision {

public TEDecisionWithAlignment(DecisionLabel label, Double confidence, String pairID, JCas casWithAlignment)
public TEDecisionWithAlignment(DecisionLabel label, Double confidence, String pairID, JCas casWithAlignment, Vector<FeatureValue> featureVector)
{
this.label = label;
this.confidence = confidence;
this.pairID = pairID;
this.theJCas = casWithAlignment;
this.featureVector = featureVector;
}

@Override
Expand All @@ -52,9 +55,20 @@ public JCas getJCasWithAlignment() {
return theJCas;
}

/**
* Call this method to access the "features", as they were used in the EDA.
*
* @return
*/
public Vector<FeatureValue> getFeatureVector()
{
return featureVector;
}

private final DecisionLabel label;
private final double confidence;
private final String pairID;
private final JCas theJCas;

private final Vector<FeatureValue> featureVector;

}
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package eu.excitementproject.eop.alignmentedas.p1eda.tools;
package eu.excitementproject.eop.alignmentedas.p1eda.inspector;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.apache.log4j.Logger;
import org.apache.uima.cas.FSIterator;
import org.apache.uima.jcas.JCas;
import org.apache.uima.jcas.cas.TOP;

import eu.excitement.type.entailment.Pair;
import eu.excitementproject.eop.alignmentedas.p1eda.P1EDATemplate;
import eu.excitementproject.eop.alignmentedas.p1eda.sandbox.WithVO;
import eu.excitementproject.eop.alignmentedas.p1eda.sandbox.WithoutVO;
//import eu.excitementproject.eop.alignmentedas.p1eda.P1EDATemplate;
//import eu.excitementproject.eop.alignmentedas.p1eda.sandbox.WithVO;
//import eu.excitementproject.eop.alignmentedas.p1eda.sandbox.WithoutVO;
import eu.excitementproject.eop.common.DecisionLabel;
import eu.excitementproject.eop.common.EDABasic;
import eu.excitementproject.eop.common.EDAException;
import eu.excitementproject.eop.common.TEDecision;
import eu.excitementproject.eop.lap.LAPException;
import eu.excitementproject.eop.lap.PlatformCASProber;
import static eu.excitementproject.eop.alignmentedas.p1eda.inspector.InspectUtilsJCasAndLinks.*;

/**
* This class holds some static methods that are useful, or needed to
Expand All @@ -31,45 +31,26 @@ public class CompareTwoEDAs {
// TODO: Two lists output? instead of one? a.) improved on EDA2. b.) degraded on EDA2.
// TODO: startTraining(XML file?, modelToStore)? (on template side)
// TODO: include training...


public static void main(String[] args)
{
try {
P1EDATemplate withVO = new WithVO();
P1EDATemplate withoutVO = new WithoutVO();

withVO.initialize(new File("target/withVO.cmodel"));
withoutVO.initialize(new File("target/withoutVO.cmodel"));

logDiffPairs(withVO, withoutVO, new File("target/testingXmis"));
}
catch (Exception e)
{
System.err.println("Run stopped with Exception: " + e.getMessage());
}
}





/**
* Pass two initialized (ready to be call process()) EDAs,
* and one dir Path to XMI files.
*
* The utility will print out to Logger; all pair IDs that the two given
* EDAs did *not* agree.
* EDAs did *not* agree. And the method will also return the result as a list of IDs.
*
* @param eda1
* @param eda2
* @param dirXMITestSet
* @param eda1 first EDA
* @param eda2 second EDA
* @param dirXMITestSet directory (File object) to where already a RTE test set has been properly processed into a set of XMI files.
* @return List<String>, which that holds IDs (of that test set pairs) where the two EDAs disagreed on the decision.
*/
static public void logDiffPairs(EDABasic<? extends TEDecision> eda1, EDABasic<? extends TEDecision> eda2, File dirXMITestSet) throws Exception
static public List<String> getDiffPairs(EDABasic<? extends TEDecision> eda1, EDABasic<? extends TEDecision> eda2, File dirXMITestSet) throws Exception
{
// well. Run each of the XMI pairs on two EDAs, and keep the
// pairID, and results.
// oh, by the way, keep general accuracy too. ...

List<String> diffPairIDs = new ArrayList<String>();
HashMap<String, String> diffPairs = new HashMap<String, String>(); // diffPairs.get("id") = "eda 1 result (confidence), eda2 result(confidence), gold result"
int countEda1Correct = 0;
int countEda2Correct = 0;
Expand Down Expand Up @@ -110,7 +91,7 @@ static public void logDiffPairs(EDABasic<? extends TEDecision> eda1, EDABasic<?
}

// get pair ID and gold annotation
String pairId = getTEPairID(pairForEDA1);
String pairId = InspectUtilsJCasAndLinks.getTEPairID(pairForEDA1);
logger.info("comparing two edas on pair " + pairId);
DecisionLabel gold = getGoldLabel(pairForEDA1);

Expand All @@ -135,8 +116,8 @@ static public void logDiffPairs(EDABasic<? extends TEDecision> eda1, EDABasic<?
{
logger.debug("different results on pair " + pairId + ": " + eda1s.getDecision().toString() + ", " + eda2s.getDecision().toString());
diffPairs.put(pairId, eda1s.getDecision().toString() + ", " + eda2s.getDecision().toString() + " (gold: " + gold.toString() + ")");
}

diffPairIDs.add(pairId);
}
}

logger.info("In total, " + countTotalPair + " pairs tested");
Expand All @@ -149,59 +130,14 @@ static public void logDiffPairs(EDABasic<? extends TEDecision> eda1, EDABasic<?
logger.info(s + ": " + diffPairs.get(s));
}

return diffPairIDs;
}

private static Logger logger = Logger.getLogger(CompareTwoEDAs.class);

public static DecisionLabel getGoldLabel(JCas aJCas) throws EDAException
{
String labelString;
DecisionLabel labelEnum;

FSIterator<TOP> iter = aJCas.getJFSIndexRepository().getAllIndexedFS(Pair.type);
if (iter.hasNext())
{
Pair p = (Pair) iter.next();
labelString = p.getGoldAnswer();

if (labelString == null) // there is no gold answer annotated in this Pair
return null;

labelEnum = DecisionLabel.getLabelFor(labelString);

if (iter.hasNext())
{
logger.warn("This JCas has more than one TE Pairs: This P1EDA template only processes single-pair inputs. Any additional pairs are being ignored, and only the first Pair will be processed.");
}
return labelEnum;
}
else
{
throw new EDAException("Input CAS is not well-formed CAS as EOP EDA input: missing TE pair");
}
}
//
// privates
//

public static String getTEPairID(JCas aJCas) throws EDAException
{
String id = null;

// check entailment pair,
FSIterator<TOP> iter = aJCas.getJFSIndexRepository().getAllIndexedFS(Pair.type);
if (iter.hasNext())
{
Pair p = (Pair) iter.next();
id = p.getPairID();

if (iter.hasNext())
{
logger.warn("This JCas has more than one TE Pairs: This P1EDA template only processes single-pair inputs. Any additional pairs are being ignored, and only the first Pair will be processed.");
}
return id;
}
else
{
throw new EDAException("Input CAS is not well-formed CAS as EOP EDA input: missing TE pair");
}
}
// logger
private static Logger logger = Logger.getLogger(CompareTwoEDAs.class);

}
Loading

0 comments on commit 6c97b1d

Please sign in to comment.