Package org.apache.uima.ruta.verbalize

Examples of org.apache.uima.ruta.verbalize.RutaVerbalizer


public class ConditionVerbalizerTest {

  @Test
  public void test() {
    RutaVerbalizer v = new RutaVerbalizer();
    List<TypeExpression> typeExprList = new ArrayList<TypeExpression>();
    List<StringExpression> stringExprList = new ArrayList<StringExpression>();
    String var = "anyVar";
    StringExpression varExpr = new ReferenceNumberExpression(var);
    TypeExpression typeExpr1 = new SimpleTypeExpression("Type1");
    TypeExpression typeExpr2 = new ReferenceTypeExpression("typeVar");
    typeExprList.add(typeExpr1);
    typeExprList.add(typeExpr2);
    NumberExpression numExpr1 = new SimpleNumberExpression(4);
    NumberExpression numExpr2 = new ReferenceNumberExpression("numVar");
    BooleanExpression boolExpr1 = new SimpleBooleanExpression(true);
    StringExpression stringExpr = new SimpleStringExpression("string");
    stringExprList.add(stringExpr);
    TypeListExpression typeListExpr = new SimpleTypeListExpression(typeExprList);
    StringListExpression stringListExpr = new SimpleStringListExpression(stringExprList);
    AbstractRutaCondition c = null;
    String s = null;

    // AFTER
    c = new AfterCondition(typeExpr1);
    s = v.verbalize(c);
    assertEquals("AFTER(Type1)", s);

    c = new AfterCondition(typeExpr2);
    s = v.verbalize(c);
    assertEquals("AFTER(typeVar)", s);

    c = new AfterCondition(typeListExpr);
    s = v.verbalize(c);
    assertEquals("AFTER({Type1, typeVar})", s);

    // AND
    List<AbstractRutaCondition> conds = new ArrayList<AbstractRutaCondition>();
    AbstractRutaCondition c1 = new AfterCondition(typeExpr2);
    AbstractRutaCondition c2 = new AfterCondition(typeListExpr);
    conds.add(c1);
    conds.add(c2);
    c = new AndCondition(conds);
    s = v.verbalize(c);
    assertEquals("AND(AFTER(typeVar), AFTER({Type1, typeVar}))", s);

    // BEFORE
    c = new BeforeCondition(typeExpr1);
    s = v.verbalize(c);
    assertEquals("BEFORE(Type1)", s);

    c = new BeforeCondition(typeExpr2);
    s = v.verbalize(c);
    assertEquals("BEFORE(typeVar)", s);

    c = new BeforeCondition(typeListExpr);
    s = v.verbalize(c);
    assertEquals("BEFORE({Type1, typeVar})", s);

    // CONTAINS
    c = new ContainsCondition(typeExpr1, numExpr1, numExpr2, boolExpr1);
    s = v.verbalize(c);
    assertEquals("CONTAINS(Type1, 4, numVar, true)", s);

    c = new ContainsCondition(typeExpr2, null, null, null);
    s = v.verbalize(c);
    assertEquals("CONTAINS(typeVar)", s);

    c = new ContainsCondition(typeListExpr, typeExpr2, null, null, null);
    s = v.verbalize(c);
    assertEquals("CONTAINS({Type1, typeVar}, typeVar)", s);

    // CONTEXTCOUNT
    c = new ContextCountCondition(typeExpr1, numExpr1, numExpr2, var);
    s = v.verbalize(c);
    assertEquals("CONTEXTCOUNT(Type1, 4, numVar, anyVar)", s);

    // COUNT
    c = new CountCondition(typeExpr1, numExpr1, numExpr2, var);
    s = v.verbalize(c);
    assertEquals("COUNT(Type1, 4, numVar, anyVar)", s);

    c = new CountCondition(typeListExpr, typeExpr2, null, null, null);
    s = v.verbalize(c);
    assertEquals("COUNT({Type1, typeVar}, typeVar)", s);

    // CURRENTCOUNT
    c = new CurrentCountCondition(typeExpr1, numExpr1, numExpr2, var);
    s = v.verbalize(c);
    assertEquals("CURRENTCOUNT(Type1, 4, numVar, anyVar)", s);

    // ENDSWITH
    c = new EndsWithCondition(typeExpr1);
    s = v.verbalize(c);
    assertEquals("ENDSWITH(Type1)", s);

    c = new EndsWithCondition(typeListExpr);
    s = v.verbalize(c);
    assertEquals("ENDSWITH({Type1, typeVar})", s);

    // FEATURE
    c = new FeatureCondition(stringExpr, stringExpr);
    s = v.verbalize(c);
    assertEquals("FEATURE(\"string\", \"string\")", s);

    // IF
    c = new IfCondition(boolExpr1);
    s = v.verbalize(c);
    assertEquals("IF(true)", s);

    // INLIST
    c = new InListCondition(stringListExpr, numExpr1, boolExpr1);
    s = v.verbalize(c);
    assertEquals("INLIST({\"string\"}, 4, true)", s);

    // IS
    c = new IsCondition(typeExpr1);
    s = v.verbalize(c);
    assertEquals("IS(Type1)", s);

    c = new IsCondition(typeListExpr);
    s = v.verbalize(c);
    assertEquals("IS({Type1, typeVar})", s);

    // LAST
    c = new LastCondition(typeExpr1);
    s = v.verbalize(c);
    assertEquals("LAST(Type1)", s);

    // MOFN
    c = new MOfNCondition(conds, numExpr1, numExpr2);
    s = v.verbalize(c);
    assertEquals("MOFN(4, numVar, AFTER(typeVar), AFTER({Type1, typeVar}))", s);

    // NEAR
    c = new NearCondition(typeExpr1, numExpr1, numExpr2, boolExpr1, boolExpr1);
    s = v.verbalize(c);
    assertEquals("NEAR(Type1, 4, numVar, true, true)", s);

    // NOT
    c = new NotCondition(c1);
    s = v.verbalize(c);
    assertEquals("-AFTER(typeVar)", s);

    // OR
    c = new OrCondition(conds);
    s = v.verbalize(c);
    assertEquals("OR(AFTER(typeVar), AFTER({Type1, typeVar}))", s);

    // PARSE
    c = new ParseCondition(var);
    s = v.verbalize(c);
    assertEquals("PARSE(anyVar)", s);

    // PARTOF
    c = new PartOfCondition(typeExpr1);
    s = v.verbalize(c);
    assertEquals("PARTOF(Type1)", s);

    c = new PartOfCondition(typeListExpr);
    s = v.verbalize(c);
    assertEquals("PARTOF({Type1, typeVar})", s);

    // PARTOFNEQ
    c = new PartOfNeqCondition(typeExpr1);
    s = v.verbalize(c);
    assertEquals("PARTOFNEQ(Type1)", s);

    c = new PartOfNeqCondition(typeListExpr);
    s = v.verbalize(c);
    assertEquals("PARTOFNEQ({Type1, typeVar})", s);

    // POSITION
    c = new PositionCondition(typeExpr1, numExpr1, boolExpr1);
    s = v.verbalize(c);
    assertEquals("POSITION(Type1, 4, true)", s);

    // REGEXP
    c = new RegExpCondition(stringExpr, boolExpr1);
    s = v.verbalize(c);
    assertEquals("REGEXP(\"string\", true)", s);

    c = new RegExpCondition(varExpr, stringExpr, boolExpr1);
    s = v.verbalize(c);
    assertEquals("REGEXP(anyVar, \"string\", true)", s);

    // SCORE
    c = new ScoreCondition(numExpr1, numExpr2, var);
    s = v.verbalize(c);
    assertEquals("SCORE(4, numVar, anyVar)", s);

    // SIZE
    c = new SizeCondition(typeListExpr, numExpr1, numExpr2, var);
    s = v.verbalize(c);
    assertEquals("SIZE({Type1, typeVar}, 4, numVar, anyVar)", s);

    // STARTSWITH
    c = new StartsWithCondition(typeExpr1);
    s = v.verbalize(c);
    assertEquals("STARTSWITH(Type1)", s);

    c = new StartsWithCondition(typeListExpr);
    s = v.verbalize(c);
    assertEquals("STARTSWITH({Type1, typeVar})", s);

    // TOTALCOUNT
    c = new TotalCountCondition(typeExpr1, numExpr1, numExpr2, var);
    s = v.verbalize(c);
    assertEquals("TOTALCOUNT(Type1, 4, numVar, anyVar)", s);

    // VOTE
    c = new VoteCondition(typeExpr1, typeExpr2);
    s = v.verbalize(c);
    assertEquals("VOTE(Type1, typeVar)", s);

  }
View Full Code Here


    this.context = aContext;

    factory = new RutaExternalFactory();
    engineLoader = new RutaEngineLoader();
    verbalizer = new RutaVerbalizer();

    if (!factory.isInitialized()) {
      initializeExtensionWithClassPath();
    }
    if (!engineLoader.isInitialized()) {
View Full Code Here

TOP

Related Classes of org.apache.uima.ruta.verbalize.RutaVerbalizer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.