Package org.apache.uima.ruta.verbalize

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


      this.context = aContext;

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

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


public class ActionVerbalizerTest {

  @SuppressWarnings("unchecked")
  @Test
  public void test() {
    RutaVerbalizer v = new RutaVerbalizer();
    List<TypeExpression> typeExprList = new ArrayList<TypeExpression>();
    List<IStringExpression> stringExprList = new ArrayList<IStringExpression>();
    List<IRutaExpression> exprList = new ArrayList<IRutaExpression>();
    List<INumberExpression> indexes = new ArrayList<INumberExpression>();
    String var = "anyVar";
    TypeExpression typeExpr1 = new SimpleTypeExpression("Type1");
    TypeExpression typeExpr2 = new ReferenceTypeExpression("typeVar");
    typeExprList.add(typeExpr1);
    typeExprList.add(typeExpr2);
    INumberExpression numExpr1 = new SimpleNumberExpression(4);
    INumberExpression numExpr2 = new ReferenceNumberExpression("numVar");
    IBooleanExpression boolExpr1 = new SimpleBooleanExpression(true);
    AbstractStringExpression stringExpr = new SimpleStringExpression("string");
    stringExprList.add(stringExpr);
    exprList.add(typeExpr1);
    WordTableExpression wordTableExpr = new ReferenceWordTableExpression(var);
    WordListExpression wordListExpr = new ReferenceWordListExpression(var);
    TypeListExpression typeListExpr = new SimpleTypeListExpression(typeExprList);
    StringListExpression stringListExpr = new SimpleStringListExpression(stringExprList);
    Map<IStringExpression, IRutaExpression> stringExprMap = new HashMap<IStringExpression, IRutaExpression>();
    Map<IStringExpression, INumberExpression> stringExprNumExprMap = new HashMap<IStringExpression, INumberExpression>();
    Map<IStringExpression, TypeExpression> stringExprTypeExprMap = new HashMap<IStringExpression, TypeExpression>();
    @SuppressWarnings("rawtypes")
    ListExpression listExpr = new SimpleTypeListExpression(typeExprList);
    @SuppressWarnings("rawtypes")
    List<ListExpression> listExprList = new ArrayList<ListExpression>();
    listExprList.add(listExpr);
    stringExprMap.put(stringExpr, stringExpr);
    stringExprNumExprMap.put(stringExpr, numExpr1);
    stringExprTypeExprMap.put(stringExpr, typeExpr1);
    indexes.add(numExpr1);
    indexes.add(numExpr2);
    AbstractRutaAction a = null;
    String s = null;

    // ADD
    a = new AddAction(var, exprList);
    s = v.verbalize(a);
    assertEquals("ADD(anyVar, Type1)", s);

    // ASSIGN
    a = new AssignAction(var, stringExpr);
    s = v.verbalize(a);
    assertEquals("ASSIGN(anyVar, \"string\")", s);

    // CALL
    a = new CallAction(var);
    s = v.verbalize(a);
    assertEquals("CALL(anyVar)", s);

    // CLEAR
    a = new ClearAction(var);
    s = v.verbalize(a);
    assertEquals("CLEAR(anyVar)", s);

    // COLOR
    a = new ColorAction(typeExpr1, stringExpr, stringExpr, boolExpr1);
    s = v.verbalize(a);
    assertEquals("COLOR(Type1, \"string\", \"string\", true)", s);

    // CONFIGURE
    a = new ConfigureAction(var, stringExprMap);
    s = v.verbalize(a);
    assertEquals("CONFIGURE(anyVar, \"string\" = \"string\")", s);

    // CREATE
    a = new CreateAction(typeExpr1, stringExprMap, indexes);
    s = v.verbalize(a);
    assertEquals("CREATE(Type1, 4, numVar, \"string\" = \"string\")", s);

    // DEL
    a = new DelAction();
    s = v.verbalize(a);
    assertEquals("DEL", s);

    // DYNAMICANCHORING
    a = new DynamicAnchoringAction(boolExpr1, numExpr1, numExpr2);
    s = v.verbalize(a);
    assertEquals("DYNAMICANCHORING(true, 4, numVar)", s);

    // EXEC
    a = new ExecAction(var, typeListExpr, stringExpr);
    s = v.verbalize(a);
    assertEquals("EXEC(\"string\", anyVar, {Type1, typeVar})", s);

    // FILL
    a = new FillAction(typeExpr1, stringExprMap);
    s = v.verbalize(a);
    assertEquals("FILL(Type1, \"string\" = \"string\")", s);

    // FILTERTYPE
    a = new FilterTypeAction(typeExprList);
    s = v.verbalize(a);
    assertEquals("FILTERTYPE(Type1, typeVar)", s);

    // GATHER
    a = new GatherAction(typeExpr1, stringExprMap, indexes);
    s = v.verbalize(a);
    assertEquals("GATHER(Type1, 4, numVar, \"string\" = \"string\")", s);

    // GET
    a = new GetAction(listExpr, var, stringExpr);
    s = v.verbalize(a);
    assertEquals("GET({Type1, typeVar}, anyVar, \"string\")", s);

    // GETFEATURE
    a = new GetFeatureAction(stringExpr, var);
    s = v.verbalize(a);
    assertEquals("GETFEATURE(\"string\", anyVar)", s);

    // GETLIST
    a = new GetListAction(var, stringExpr);
    s = v.verbalize(a);
    assertEquals("GETLIST(anyVar, \"string\")", s);

    // LOG
    a = new LogAction(stringExpr, Level.INFO);
    s = v.verbalize(a);
    assertEquals("LOG(\"string\", INFO)", s);

    // MARK
    a = new MarkAction(typeExpr1, null, indexes);
    s = v.verbalize(a);
    assertEquals("MARK(Type1, 4, numVar)", s);

    // MARKFAST
    a = new MarkFastAction(typeExpr1, stringListExpr, boolExpr1, numExpr1, boolExpr1);
    s = v.verbalize(a);
    assertEquals("MARKFAST(Type1, {\"string\"}, true, 4, true)", s);

    // MARKLAST
    a = new MarkLastAction(typeExpr1);
    s = v.verbalize(a);
    assertEquals("MARKLAST(Type1)", s);

    // MARKONCE
    a = new MarkOnceAction(typeExpr1, null, indexes);
    s = v.verbalize(a);
    assertEquals("MARKONCE(Type1, 4, numVar)", s);

    // MARKSCORE
    a = new MarkAction(typeExpr1, numExpr1, indexes);
    s = v.verbalize(a);
    assertEquals("MARKSCORE(4, Type1, 4, numVar)", s);

    // MARKTABLE
    a = new MarkTableAction(typeExpr1, numExpr1, wordTableExpr, stringExprNumExprMap, boolExpr1,
            numExpr1, stringExpr, numExpr1);
    s = v.verbalize(a);
    assertEquals("MARKTABLE(Type1, 4, anyVar, \"string\" = 4, , true, 4, \"string\", 4)", s);

    // MATCHEDTEXT
    a = new MatchedTextAction(var, indexes);
    s = v.verbalize(a);
    assertEquals("MATCHEDTEXT(anyVar, 4, numVar)", s);

    // MERGE
    a = new MergeAction(boolExpr1, var, listExprList);
    s = v.verbalize(a);
    assertEquals("MERGE(true, anyVar, {Type1, typeVar})", s);

    // REMOVEDUPLICATE
    a = new RemoveDuplicateAction(var);
    s = v.verbalize(a);
    assertEquals("REMOVEDUPLICATE(anyVar)", s);

    // REPLACE
    a = new ReplaceAction(stringExpr);
    s = v.verbalize(a);
    assertEquals("REPLACE(\"string\")", s);

    // RETAINTYPE
    a = new RetainTypeAction(typeExprList);
    s = v.verbalize(a);
    assertEquals("RETAINTYPE(Type1, typeVar)", s);

    // SETFEATURE
    a = new SetFeatureAction(stringExpr, typeExpr1);
    s = v.verbalize(a);
    assertEquals("SETFEATURE(\"string\", Type1)", s);

    // SHIFT
    a = new ShiftAction(typeExpr1, indexes);
    s = v.verbalize(a);
    assertEquals("SHIFT(Type1, 4, numVar)", s);

    // TRANSFER
    a = new TransferAction(typeExpr1);
    s = v.verbalize(a);
    assertEquals("TRANSFER(Type1)", s);

    // TRIE
    a = new TrieAction(wordListExpr, stringExprTypeExprMap, boolExpr1, numExpr1, boolExpr1,
            numExpr1, stringExpr);
    s = v.verbalize(a);
    assertEquals("TRIE(\"string\" = Type1, anyVar, true, 4, true, 4, \"string\")", s);

    // UNMARK
    a = new UnmarkAction(typeExpr1, indexes, boolExpr1);
    s = v.verbalize(a);
    assertEquals("UNMARK(Type1, 4, numVar, true)", s);

    // UNMARKALL
    a = new UnmarkAllAction(typeExpr1, typeListExpr);
    s = v.verbalize(a);
    assertEquals("UNMARKALL(Type1, {Type1, typeVar})", s);

  }
View Full Code Here

public class ExpressionVerbalizerTest {

  @SuppressWarnings("unchecked")
  @Test
  public void test() {
    RutaVerbalizer v = new RutaVerbalizer();
//    List<TypeExpression> typeExprList = new ArrayList<TypeExpression>();
//    List<StringExpression> stringExprList = new ArrayList<StringExpression>();
//    List<RutaExpression> exprList = new ArrayList<RutaExpression>();
//    List<INumberExpression> indexes = new ArrayList<INumberExpression>();

//   
////    typeExprList.add(typeExpr1);
////    typeExprList.add(typeExpr2);
//   
//
//    StringExpression stringExpr = new SimpleStringExpression("string");
//    stringExprList.add(stringExpr);
////    exprList.add(typeExpr1);
//    WordTableExpression wordTableExpr = new ReferenceWordTableExpression(var);
//    WordListExpression wordListExpr = new ReferenceWordListExpression(var);
//    TypeListExpression typeListExpr = new SimpleTypeListExpression(typeExprList);
//    StringListExpression stringListExpr = new SimpleStringListExpression(stringExprList);
//    Map<StringExpression, RutaExpression> stringExprMap = new HashMap<StringExpression, RutaExpression>();
//    Map<StringExpression, INumberExpression> stringExprNumExprMap = new HashMap<StringExpression, INumberExpression>();
//    Map<StringExpression, TypeExpression> stringExprTypeExprMap = new HashMap<StringExpression, TypeExpression>();
//    @SuppressWarnings("rawtypes")
//    ListExpression listExpr = new SimpleTypeListExpression(typeExprList);
//    @SuppressWarnings("rawtypes")
//    List<ListExpression> listExprList = new ArrayList<ListExpression>();
//    listExprList.add(listExpr);
//    stringExprMap.put(stringExpr, stringExpr);
////    stringExprNumExprMap.put(stringExpr, numExpr1);
////    stringExprTypeExprMap.put(stringExpr, typeExpr1);
////    indexes.add(numExpr1);
////    indexes.add(numExpr2);

    String s = null;
  String var = "anyVar";
    TypeExpression typeExpr1 = new SimpleTypeExpression("Type1");
    TypeExpression typeExpr2 = new ReferenceTypeExpression("typeVar");
   
    List<INumberExpression> numExprList1 = new ArrayList<INumberExpression>();
    List<INumberExpression> numExprList2 = new ArrayList<INumberExpression>();
    List<String> opList1 = new ArrayList<String>();
    List<String> opList2 = new ArrayList<String>();
    INumberExpression numExpr1 = new SimpleNumberExpression(4);
    INumberExpression numExpr2 = new ReferenceNumberExpression("numVar");
    INumberExpression numExpr3 = new ReferenceNumberExpression("4.9");
    INumberExpression numExpr4 = new ReferenceNumberExpression("-4");
    numExprList1.add(numExpr1);
    numExprList1.add(numExpr2);
    opList1.add("+");
    opList2.add("*");
    INumberExpression numExpr5 = new ComposedNumberExpression(numExprList1, opList1);
    numExprList2.add(numExpr3);
    numExprList2.add(numExpr5);
    INumberExpression numExpr6 = new ComposedNumberExpression(numExprList2, opList2);
   
    s = v.verbalize(numExpr1);
    assertEquals("4", s);
    s = v.verbalize(numExpr2);
    assertEquals("numVar", s);
    s = v.verbalize(numExpr3);
    assertEquals("4.9", s);
    s = v.verbalize(numExpr4);
    assertEquals("-4", s);
    s = v.verbalize(numExpr5);
    assertEquals("4 + numVar", s);
    s = v.verbalize(numExpr6);
    assertEquals("4.9 * 4 + numVar", s);
   
   
   
    IBooleanExpression boolExpr1 = new SimpleBooleanExpression(true);
    IBooleanExpression boolExpr2 = new SimpleBooleanExpression(false);
    IBooleanExpression boolExpr3 = new ReferenceBooleanExpression(var);
    IBooleanExpression boolExpr4 = new BooleanNumberExpression(numExpr1, "==", numExpr2);
    IBooleanExpression boolExpr5 = new BooleanNumberExpression(numExpr1, "!=", numExpr2);
    IBooleanExpression boolExpr6 = new BooleanNumberExpression(numExpr1, "<=", numExpr2);
    IBooleanExpression boolExpr7 = new BooleanNumberExpression(numExpr1, ">=", numExpr2);
    IBooleanExpression boolExpr8 = new BooleanNumberExpression(numExpr1, "<", numExpr2);
    IBooleanExpression boolExpr9 = new BooleanNumberExpression(numExpr1, ">", numExpr2);
    IBooleanExpression boolExpr10 = new BooleanTypeExpression(typeExpr1, "==", typeExpr2);
    IBooleanExpression boolExpr11 = new BooleanTypeExpression(typeExpr1, "!=", typeExpr2);
   
    s = v.verbalize(boolExpr1);
    assertEquals("true", s);
    s = v.verbalize(boolExpr2);
    assertEquals("false", s);
    s = v.verbalize(boolExpr3);
    assertEquals("anyVar", s);
    s = v.verbalize(boolExpr4);
    assertEquals("4 == numVar", s);
    s = v.verbalize(boolExpr5);
    assertEquals("4 != numVar", s);
    s = v.verbalize(boolExpr6);
    assertEquals("4 <= numVar", s);
    s = v.verbalize(boolExpr7);
    assertEquals("4 >= numVar", s);
    s = v.verbalize(boolExpr8);
    assertEquals("4 < numVar", s);
    s = v.verbalize(boolExpr9);
    assertEquals("4 > numVar", s);
    s = v.verbalize(boolExpr10);
    assertEquals("Type1 == typeVar", s);
    s = v.verbalize(boolExpr11);
    assertEquals("Type1 != typeVar", s);

    List<IStringExpression> stringExprList = new ArrayList<IStringExpression>();
    AbstractStringExpression stringExpr1 = new SimpleStringExpression("string");
    AbstractStringExpression stringExpr2 = new ReferenceStringExpression(var);
    stringExprList.add(stringExpr1);
    stringExprList.add(stringExpr2);
    AbstractStringExpression stringExpr3 = new ComposedStringExpression(stringExprList);
   
    s = v.verbalize(stringExpr1);
    assertEquals("\"string\"", s);
    s = v.verbalize(stringExpr2);
    assertEquals("anyVar", s);
    s = v.verbalize(stringExpr3);
    assertEquals("\"string\" + anyVar"  , s);
   
   
    StringListExpression sle1 = new SimpleStringListExpression(stringExprList);
    StringListExpression sle2 = new ReferenceStringListExpression(var);
    s = v.verbalize(sle1);
    assertEquals("{\"string\", anyVar}", s);
    s = v.verbalize(sle2);
    assertEquals("anyVar", s);
   
    List<IBooleanExpression> boolExprList = new ArrayList<IBooleanExpression>();
    boolExprList.add(boolExpr1);
    boolExprList.add(boolExpr3);
    BooleanListExpression ble1 = new SimpleBooleanListExpression(boolExprList);
    BooleanListExpression ble2 = new ReferenceBooleanListExpression(var);
    s = v.verbalize(ble1);
    assertEquals("{true, anyVar}", s);
    s = v.verbalize(ble2);
    assertEquals("anyVar", s);
   
    List<INumberExpression> numExprList = new ArrayList<INumberExpression>();
    numExprList.add(numExpr1);
    numExprList.add(numExpr3);
    NumberListExpression nle1 = new SimpleNumberListExpression(numExprList);
    NumberListExpression nle2 = new ReferenceNumberListExpression(var);
    s = v.verbalize(nle1);
    assertEquals("{4, 4.9}", s);
    s = v.verbalize(nle2);
    assertEquals("anyVar", s);
   
    List<TypeExpression> typeExprList = new ArrayList<TypeExpression>();
    typeExprList.add(typeExpr1);
    typeExprList.add(typeExpr2);
    TypeListExpression tle1 = new SimpleTypeListExpression(typeExprList);
    TypeListExpression tle2 = new ReferenceTypeListExpression(var);
    s = v.verbalize(tle1);
    assertEquals("{Type1, typeVar}", s);
    s = v.verbalize(tle2);
    assertEquals("anyVar", s);
   
  }
View Full Code Here

public class ConditionVerbalizerTest {

  @Test
  public void test() {
    RutaVerbalizer v = new RutaVerbalizer();
    List<TypeExpression> typeExprList = new ArrayList<TypeExpression>();
    List<IStringExpression> stringExprList = new ArrayList<IStringExpression>();
    String var = "anyVar";
    IStringExpression varExpr = new ReferenceNumberExpression(var);
    TypeExpression typeExpr1 = new SimpleTypeExpression("Type1");
    TypeExpression typeExpr2 = new ReferenceTypeExpression("typeVar");
    typeExprList.add(typeExpr1);
    typeExprList.add(typeExpr2);
    INumberExpression numExpr1 = new SimpleNumberExpression(4);
    INumberExpression numExpr2 = new ReferenceNumberExpression("numVar");
    IBooleanExpression boolExpr1 = new SimpleBooleanExpression(true);
    IStringExpression 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, stringExpr);
    s = v.verbalize(c);
    assertEquals("INLIST({\"string\"}, \"string\")", 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();

      resourceManager = UIMAFramework.newDefaultResourceManager();
      String dataPath = "";
      if (descriptorPaths != null) {
        for (String path : descriptorPaths) {
View Full Code Here

public class ActionVerbalizerTest {

  @SuppressWarnings("unchecked")
  @Test
  public void test() {
    RutaVerbalizer v = new RutaVerbalizer();
    List<TypeExpression> typeExprList = new ArrayList<TypeExpression>();
    List<StringExpression> stringExprList = new ArrayList<StringExpression>();
    List<RutaExpression> exprList = new ArrayList<RutaExpression>();
    List<NumberExpression> indexes = new ArrayList<NumberExpression>();
    String var = "anyVar";
    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);
    exprList.add(typeExpr1);
    WordTableExpression wordTableExpr = new ReferenceWordTableExpression(var);
    WordListExpression wordListExpr = new ReferenceWordListExpression(var);
    TypeListExpression typeListExpr = new SimpleTypeListExpression(typeExprList);
    StringListExpression stringListExpr = new SimpleStringListExpression(stringExprList);
    Map<StringExpression, RutaExpression> stringExprMap = new HashMap<StringExpression, RutaExpression>();
    Map<StringExpression, NumberExpression> stringExprNumExprMap = new HashMap<StringExpression, NumberExpression>();
    Map<StringExpression, TypeExpression> stringExprTypeExprMap = new HashMap<StringExpression, TypeExpression>();
    @SuppressWarnings("rawtypes")
    ListExpression listExpr = new SimpleTypeListExpression(typeExprList);
    @SuppressWarnings("rawtypes")
    List<ListExpression> listExprList = new ArrayList<ListExpression>();
    listExprList.add(listExpr);
    stringExprMap.put(stringExpr, stringExpr);
    stringExprNumExprMap.put(stringExpr, numExpr1);
    stringExprTypeExprMap.put(stringExpr, typeExpr1);
    indexes.add(numExpr1);
    indexes.add(numExpr2);
    AbstractRutaAction a = null;
    String s = null;

    // ADD
    a = new AddAction(var, exprList);
    s = v.verbalize(a);
    assertEquals("ADD(anyVar, Type1)", s);

    // ASSIGN
    a = new AssignAction(var, stringExpr);
    s = v.verbalize(a);
    assertEquals("ASSIGN(anyVar, \"string\")", s);

    // CALL
    a = new CallAction(var);
    s = v.verbalize(a);
    assertEquals("CALL(anyVar)", s);

    // CLEAR
    a = new ClearAction(var);
    s = v.verbalize(a);
    assertEquals("CLEAR(anyVar)", s);

    // COLOR
    a = new ColorAction(typeExpr1, stringExpr, stringExpr, boolExpr1);
    s = v.verbalize(a);
    assertEquals("COLOR(Type1, \"string\", \"string\", true)", s);

    // CONFIGURE
    a = new ConfigureAction(var, stringExprMap);
    s = v.verbalize(a);
    assertEquals("CONFIGURE(anyVar, \"string\" = \"string\")", s);

    // CREATE
    a = new CreateAction(typeExpr1, stringExprMap, indexes);
    s = v.verbalize(a);
    assertEquals("CREATE(Type1, 4, numVar, \"string\" = \"string\")", s);

    // DEL
    a = new DelAction();
    s = v.verbalize(a);
    assertEquals("DEL", s);

    // DYNAMICANCHORING
    a = new DynamicAnchoringAction(boolExpr1, numExpr1, numExpr2);
    s = v.verbalize(a);
    assertEquals("DYNAMICANCHORING(true, 4, numVar)", s);

    // EXEC
    a = new ExecAction(var, typeListExpr);
    s = v.verbalize(a);
    assertEquals("EXEC(anyVar, {Type1, typeVar})", s);

    // FILL
    a = new FillAction(typeExpr1, stringExprMap);
    s = v.verbalize(a);
    assertEquals("FILL(Type1, \"string\" = \"string\")", s);

    // FILTERTYPE
    a = new FilterTypeAction(typeExprList);
    s = v.verbalize(a);
    assertEquals("FILTERTYPE(Type1, typeVar)", s);

    // GATHER
    a = new GatherAction(typeExpr1, stringExprMap, indexes);
    s = v.verbalize(a);
    assertEquals("GATHER(Type1, 4, numVar, \"string\" = \"string\")", s);

    // GET
    a = new GetAction(listExpr, var, stringExpr);
    s = v.verbalize(a);
    assertEquals("GET({Type1, typeVar}, anyVar, \"string\")", s);

    // GETFEATURE
    a = new GetFeatureAction(stringExpr, var);
    s = v.verbalize(a);
    assertEquals("GETFEATURE(\"string\", anyVar)", s);

    // GETLIST
    a = new GetListAction(var, stringExpr);
    s = v.verbalize(a);
    assertEquals("GETLIST(anyVar, \"string\")", s);

    // LOG
    a = new LogAction(stringExpr, Level.INFO);
    s = v.verbalize(a);
    assertEquals("LOG(\"string\", INFO)", s);

    // MARK
    a = new MarkAction(typeExpr1, null, indexes);
    s = v.verbalize(a);
    assertEquals("MARK(Type1, 4, numVar)", s);

    // MARKFAST
    a = new MarkFastAction(typeExpr1, stringListExpr, boolExpr1, numExpr1, boolExpr1);
    s = v.verbalize(a);
    assertEquals("MARKFAST(Type1, {\"string\"}, true, 4, true)", s);

    // MARKLAST
    a = new MarkLastAction(typeExpr1);
    s = v.verbalize(a);
    assertEquals("MARKLAST(Type1)", s);

    // MARKONCE
    a = new MarkOnceAction(typeExpr1, null, indexes);
    s = v.verbalize(a);
    assertEquals("MARKONCE(Type1, 4, numVar)", s);

    // MARKSCORE
    a = new MarkAction(typeExpr1, numExpr1, indexes);
    s = v.verbalize(a);
    assertEquals("MARKSCORE(4, Type1, 4, numVar)", s);

    // MARKTABLE
    a = new MarkTableAction(typeExpr1, numExpr1, wordTableExpr, stringExprNumExprMap, boolExpr1,
            numExpr1, stringExpr, numExpr1);
    s = v.verbalize(a);
    assertEquals("MARKTABLE(Type1, 4, anyVar, \"string\" = 4, , true, 4, \"string\", 4)", s);

    // MATCHEDTEXT
    a = new MatchedTextAction(var, indexes);
    s = v.verbalize(a);
    assertEquals("MATCHEDTEXT(anyVar, 4, numVar)", s);

    // MERGE
    a = new MergeAction(boolExpr1, var, listExprList);
    s = v.verbalize(a);
    assertEquals("MERGE(true, anyVar, {Type1, typeVar})", s);

    // REMOVEDUPLICATE
    a = new RemoveDuplicateAction(var);
    s = v.verbalize(a);
    assertEquals("REMOVEDUPLICATE(anyVar)", s);

    // REPLACE
    a = new ReplaceAction(stringExpr);
    s = v.verbalize(a);
    assertEquals("REPLACE(\"string\")", s);

    // RETAINTYPE
    a = new RetainTypeAction(typeExprList);
    s = v.verbalize(a);
    assertEquals("RETAINTYPE(Type1, typeVar)", s);

    // SETFEATURE
    a = new SetFeatureAction(stringExpr, typeExpr1);
    s = v.verbalize(a);
    assertEquals("SETFEATURE(\"string\", Type1)", s);

    // SHIFT
    a = new ShiftAction(typeExpr1, indexes);
    s = v.verbalize(a);
    assertEquals("SHIFT(Type1, 4, numVar)", s);

    // TRANSFER
    a = new TransferAction(typeExpr1);
    s = v.verbalize(a);
    assertEquals("TRANSFER(Type1)", s);

    // TRIE
    a = new TrieAction(wordListExpr, stringExprTypeExprMap, boolExpr1, numExpr1, boolExpr1,
            numExpr1, stringExpr);
    s = v.verbalize(a);
    assertEquals("TRIE(\"string\" = Type1, anyVar, true, 4, true, 4, \"string\")", s);

    // UNMARK
    a = new UnmarkAction(typeExpr1, indexes, boolExpr1);
    s = v.verbalize(a);
    assertEquals("UNMARK(Type1, 4, numVar, true)", s);

    // UNMARKALL
    a = new UnmarkAllAction(typeExpr1, typeListExpr);
    s = v.verbalize(a);
    assertEquals("UNMARKALL(Type1, {Type1, typeVar})", s);

  }
View Full Code Here

    this.context = aContext;

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

    localTSDMap = new HashMap<String, TypeSystemDescription>();

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

public class ExpressionVerbalizerTest {

  @SuppressWarnings("unchecked")
  @Test
  public void test() {
    RutaVerbalizer v = new RutaVerbalizer();
//    List<TypeExpression> typeExprList = new ArrayList<TypeExpression>();
//    List<StringExpression> stringExprList = new ArrayList<StringExpression>();
//    List<RutaExpression> exprList = new ArrayList<RutaExpression>();
//    List<NumberExpression> indexes = new ArrayList<NumberExpression>();

//   
////    typeExprList.add(typeExpr1);
////    typeExprList.add(typeExpr2);
//   
//
//    StringExpression stringExpr = new SimpleStringExpression("string");
//    stringExprList.add(stringExpr);
////    exprList.add(typeExpr1);
//    WordTableExpression wordTableExpr = new ReferenceWordTableExpression(var);
//    WordListExpression wordListExpr = new ReferenceWordListExpression(var);
//    TypeListExpression typeListExpr = new SimpleTypeListExpression(typeExprList);
//    StringListExpression stringListExpr = new SimpleStringListExpression(stringExprList);
//    Map<StringExpression, RutaExpression> stringExprMap = new HashMap<StringExpression, RutaExpression>();
//    Map<StringExpression, NumberExpression> stringExprNumExprMap = new HashMap<StringExpression, NumberExpression>();
//    Map<StringExpression, TypeExpression> stringExprTypeExprMap = new HashMap<StringExpression, TypeExpression>();
//    @SuppressWarnings("rawtypes")
//    ListExpression listExpr = new SimpleTypeListExpression(typeExprList);
//    @SuppressWarnings("rawtypes")
//    List<ListExpression> listExprList = new ArrayList<ListExpression>();
//    listExprList.add(listExpr);
//    stringExprMap.put(stringExpr, stringExpr);
////    stringExprNumExprMap.put(stringExpr, numExpr1);
////    stringExprTypeExprMap.put(stringExpr, typeExpr1);
////    indexes.add(numExpr1);
////    indexes.add(numExpr2);

    String s = null;
  String var = "anyVar";
    TypeExpression typeExpr1 = new SimpleTypeExpression("Type1");
    TypeExpression typeExpr2 = new ReferenceTypeExpression("typeVar");
   
    List<NumberExpression> numExprList1 = new ArrayList<NumberExpression>();
    List<NumberExpression> numExprList2 = new ArrayList<NumberExpression>();
    List<String> opList1 = new ArrayList<String>();
    List<String> opList2 = new ArrayList<String>();
    NumberExpression numExpr1 = new SimpleNumberExpression(4);
    NumberExpression numExpr2 = new ReferenceNumberExpression("numVar");
    NumberExpression numExpr3 = new ReferenceNumberExpression("4.9");
    NumberExpression numExpr4 = new ReferenceNumberExpression("-4");
    numExprList1.add(numExpr1);
    numExprList1.add(numExpr2);
    opList1.add("+");
    opList2.add("*");
    NumberExpression numExpr5 = new ComposedNumberExpression(numExprList1, opList1);
    numExprList2.add(numExpr3);
    numExprList2.add(numExpr5);
    NumberExpression numExpr6 = new ComposedNumberExpression(numExprList2, opList2);
   
    s = v.verbalize(numExpr1);
    assertEquals("4", s);
    s = v.verbalize(numExpr2);
    assertEquals("numVar", s);
    s = v.verbalize(numExpr3);
    assertEquals("4.9", s);
    s = v.verbalize(numExpr4);
    assertEquals("-4", s);
    s = v.verbalize(numExpr5);
    assertEquals("4 + numVar", s);
    s = v.verbalize(numExpr6);
    assertEquals("4.9 * 4 + numVar", s);
   
   
   
    BooleanExpression boolExpr1 = new SimpleBooleanExpression(true);
    BooleanExpression boolExpr2 = new SimpleBooleanExpression(false);
    BooleanExpression boolExpr3 = new ReferenceBooleanExpression(var);
    BooleanExpression boolExpr4 = new BooleanNumberExpression(numExpr1, "==", numExpr2);
    BooleanExpression boolExpr5 = new BooleanNumberExpression(numExpr1, "!=", numExpr2);
    BooleanExpression boolExpr6 = new BooleanNumberExpression(numExpr1, "<=", numExpr2);
    BooleanExpression boolExpr7 = new BooleanNumberExpression(numExpr1, ">=", numExpr2);
    BooleanExpression boolExpr8 = new BooleanNumberExpression(numExpr1, "<", numExpr2);
    BooleanExpression boolExpr9 = new BooleanNumberExpression(numExpr1, ">", numExpr2);
    BooleanExpression boolExpr10 = new BooleanTypeExpression(typeExpr1, "==", typeExpr2);
    BooleanExpression boolExpr11 = new BooleanTypeExpression(typeExpr1, "!=", typeExpr2);
   
    s = v.verbalize(boolExpr1);
    assertEquals("true", s);
    s = v.verbalize(boolExpr2);
    assertEquals("false", s);
    s = v.verbalize(boolExpr3);
    assertEquals("anyVar", s);
    s = v.verbalize(boolExpr4);
    assertEquals("4 == numVar", s);
    s = v.verbalize(boolExpr5);
    assertEquals("4 != numVar", s);
    s = v.verbalize(boolExpr6);
    assertEquals("4 <= numVar", s);
    s = v.verbalize(boolExpr7);
    assertEquals("4 >= numVar", s);
    s = v.verbalize(boolExpr8);
    assertEquals("4 < numVar", s);
    s = v.verbalize(boolExpr9);
    assertEquals("4 > numVar", s);
    s = v.verbalize(boolExpr10);
    assertEquals("Type1 == typeVar", s);
    s = v.verbalize(boolExpr11);
    assertEquals("Type1 != typeVar", s);

    List<StringExpression> stringExprList = new ArrayList<StringExpression>();
    StringExpression stringExpr1 = new SimpleStringExpression("string");
    StringExpression stringExpr2 = new ReferenceStringExpression(var);
    stringExprList.add(stringExpr1);
    stringExprList.add(stringExpr2);
    StringExpression stringExpr3 = new ComposedStringExpression(stringExprList);
   
    s = v.verbalize(stringExpr1);
    assertEquals("\"string\"", s);
    s = v.verbalize(stringExpr2);
    assertEquals("anyVar", s);
    s = v.verbalize(stringExpr3);
    assertEquals("\"string\" + anyVar"  , s);
   
   
    StringListExpression sle1 = new SimpleStringListExpression(stringExprList);
    StringListExpression sle2 = new ReferenceStringListExpression(var);
    s = v.verbalize(sle1);
    assertEquals("{\"string\", anyVar}", s);
    s = v.verbalize(sle2);
    assertEquals("anyVar", s);
   
    List<BooleanExpression> boolExprList = new ArrayList<BooleanExpression>();
    boolExprList.add(boolExpr1);
    boolExprList.add(boolExpr3);
    BooleanListExpression ble1 = new SimpleBooleanListExpression(boolExprList);
    BooleanListExpression ble2 = new ReferenceBooleanListExpression(var);
    s = v.verbalize(ble1);
    assertEquals("{true, anyVar}", s);
    s = v.verbalize(ble2);
    assertEquals("anyVar", s);
   
    List<NumberExpression> numExprList = new ArrayList<NumberExpression>();
    numExprList.add(numExpr1);
    numExprList.add(numExpr3);
    NumberListExpression nle1 = new SimpleNumberListExpression(numExprList);
    NumberListExpression nle2 = new ReferenceNumberListExpression(var);
    s = v.verbalize(nle1);
    assertEquals("{4, 4.9}", s);
    s = v.verbalize(nle2);
    assertEquals("anyVar", s);
   
    List<TypeExpression> typeExprList = new ArrayList<TypeExpression>();
    typeExprList.add(typeExpr1);
    typeExprList.add(typeExpr2);
    TypeListExpression tle1 = new SimpleTypeListExpression(typeExprList);
    TypeListExpression tle2 = new ReferenceTypeListExpression(var);
    s = v.verbalize(tle1);
    assertEquals("{Type1, typeVar}", s);
    s = v.verbalize(tle2);
    assertEquals("anyVar", s);
   
  }
View Full Code Here

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";
    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(var, 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

public class ActionVerbalizerTest {

  @SuppressWarnings("unchecked")
  @Test
  public void test() {
    RutaVerbalizer v = new RutaVerbalizer();
    List<TypeExpression> typeExprList = new ArrayList<TypeExpression>();
    List<StringExpression> stringExprList = new ArrayList<StringExpression>();
    List<RutaExpression> exprList = new ArrayList<RutaExpression>();
    List<NumberExpression> indexes = new ArrayList<NumberExpression>();
    String var = "anyVar";
    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);
    exprList.add(typeExpr1);
    WordTableExpression wordTableExpr = new ReferenceWordTableExpression(var);
    WordListExpression wordListExpr = new ReferenceWordListExpression(var);
    TypeListExpression typeListExpr = new SimpleTypeListExpression(typeExprList);
    StringListExpression stringListExpr = new SimpleStringListExpression(stringExprList);
    Map<StringExpression, RutaExpression> stringExprMap = new HashMap<StringExpression, RutaExpression>();
    Map<StringExpression, NumberExpression> stringExprNumExprMap = new HashMap<StringExpression, NumberExpression>();
    Map<StringExpression, TypeExpression> stringExprTypeExprMap = new HashMap<StringExpression, TypeExpression>();
    @SuppressWarnings("rawtypes")
    ListExpression listExpr = new SimpleTypeListExpression(typeExprList);
    @SuppressWarnings("rawtypes")
    List<ListExpression> listExprList = new ArrayList<ListExpression>();
    listExprList.add(listExpr);
    stringExprMap.put(stringExpr, stringExpr);
    stringExprNumExprMap.put(stringExpr, numExpr1);
    stringExprTypeExprMap.put(stringExpr, typeExpr1);
    indexes.add(numExpr1);
    indexes.add(numExpr2);
    AbstractRutaAction a = null;
    String s = null;

    // ADD
    a = new AddAction(var, exprList);
    s = v.verbalize(a);
    assertEquals("ADD(anyVar, Type1)", s);

    // ASSIGN
    a = new AssignAction(var, stringExpr);
    s = v.verbalize(a);
    assertEquals("ASSIGN(anyVar, \"string\")", s);

    // CALL
    a = new CallAction(var);
    s = v.verbalize(a);
    assertEquals("CALL(anyVar)", s);

    // CLEAR
    a = new ClearAction(var);
    s = v.verbalize(a);
    assertEquals("CLEAR(anyVar)", s);

    // COLOR
    a = new ColorAction(typeExpr1, stringExpr, stringExpr, boolExpr1);
    s = v.verbalize(a);
    assertEquals("COLOR(Type1, \"string\", \"string\", true)", s);

    // CONFIGURE
    a = new ConfigureAction(var, stringExprMap);
    s = v.verbalize(a);
    assertEquals("CONFIGURE(anyVar, \"string\" = \"string\")", s);

    // CREATE
    a = new CreateAction(typeExpr1, stringExprMap, indexes);
    s = v.verbalize(a);
    assertEquals("CREATE(Type1, 4, numVar, \"string\" = \"string\")", s);

    // DEL
    a = new DelAction();
    s = v.verbalize(a);
    assertEquals("DEL", s);

    // DYNAMICANCHORING
    a = new DynamicAnchoringAction(boolExpr1, numExpr1, numExpr2);
    s = v.verbalize(a);
    assertEquals("DYNAMICANCHORING(true, 4, numVar)", s);

    // EXEC
    a = new ExecAction(var, typeListExpr, stringExpr);
    s = v.verbalize(a);
    assertEquals("EXEC(\"string\", anyVar, {Type1, typeVar})", s);

    // FILL
    a = new FillAction(typeExpr1, stringExprMap);
    s = v.verbalize(a);
    assertEquals("FILL(Type1, \"string\" = \"string\")", s);

    // FILTERTYPE
    a = new FilterTypeAction(typeExprList);
    s = v.verbalize(a);
    assertEquals("FILTERTYPE(Type1, typeVar)", s);

    // GATHER
    a = new GatherAction(typeExpr1, stringExprMap, indexes);
    s = v.verbalize(a);
    assertEquals("GATHER(Type1, 4, numVar, \"string\" = \"string\")", s);

    // GET
    a = new GetAction(listExpr, var, stringExpr);
    s = v.verbalize(a);
    assertEquals("GET({Type1, typeVar}, anyVar, \"string\")", s);

    // GETFEATURE
    a = new GetFeatureAction(stringExpr, var);
    s = v.verbalize(a);
    assertEquals("GETFEATURE(\"string\", anyVar)", s);

    // GETLIST
    a = new GetListAction(var, stringExpr);
    s = v.verbalize(a);
    assertEquals("GETLIST(anyVar, \"string\")", s);

    // LOG
    a = new LogAction(stringExpr, Level.INFO);
    s = v.verbalize(a);
    assertEquals("LOG(\"string\", INFO)", s);

    // MARK
    a = new MarkAction(typeExpr1, null, indexes);
    s = v.verbalize(a);
    assertEquals("MARK(Type1, 4, numVar)", s);

    // MARKFAST
    a = new MarkFastAction(typeExpr1, stringListExpr, boolExpr1, numExpr1, boolExpr1);
    s = v.verbalize(a);
    assertEquals("MARKFAST(Type1, {\"string\"}, true, 4, true)", s);

    // MARKLAST
    a = new MarkLastAction(typeExpr1);
    s = v.verbalize(a);
    assertEquals("MARKLAST(Type1)", s);

    // MARKONCE
    a = new MarkOnceAction(typeExpr1, null, indexes);
    s = v.verbalize(a);
    assertEquals("MARKONCE(Type1, 4, numVar)", s);

    // MARKSCORE
    a = new MarkAction(typeExpr1, numExpr1, indexes);
    s = v.verbalize(a);
    assertEquals("MARKSCORE(4, Type1, 4, numVar)", s);

    // MARKTABLE
    a = new MarkTableAction(typeExpr1, numExpr1, wordTableExpr, stringExprNumExprMap, boolExpr1,
            numExpr1, stringExpr, numExpr1);
    s = v.verbalize(a);
    assertEquals("MARKTABLE(Type1, 4, anyVar, \"string\" = 4, , true, 4, \"string\", 4)", s);

    // MATCHEDTEXT
    a = new MatchedTextAction(var, indexes);
    s = v.verbalize(a);
    assertEquals("MATCHEDTEXT(anyVar, 4, numVar)", s);

    // MERGE
    a = new MergeAction(boolExpr1, var, listExprList);
    s = v.verbalize(a);
    assertEquals("MERGE(true, anyVar, {Type1, typeVar})", s);

    // REMOVEDUPLICATE
    a = new RemoveDuplicateAction(var);
    s = v.verbalize(a);
    assertEquals("REMOVEDUPLICATE(anyVar)", s);

    // REPLACE
    a = new ReplaceAction(stringExpr);
    s = v.verbalize(a);
    assertEquals("REPLACE(\"string\")", s);

    // RETAINTYPE
    a = new RetainTypeAction(typeExprList);
    s = v.verbalize(a);
    assertEquals("RETAINTYPE(Type1, typeVar)", s);

    // SETFEATURE
    a = new SetFeatureAction(stringExpr, typeExpr1);
    s = v.verbalize(a);
    assertEquals("SETFEATURE(\"string\", Type1)", s);

    // SHIFT
    a = new ShiftAction(typeExpr1, indexes);
    s = v.verbalize(a);
    assertEquals("SHIFT(Type1, 4, numVar)", s);

    // TRANSFER
    a = new TransferAction(typeExpr1);
    s = v.verbalize(a);
    assertEquals("TRANSFER(Type1)", s);

    // TRIE
    a = new TrieAction(wordListExpr, stringExprTypeExprMap, boolExpr1, numExpr1, boolExpr1,
            numExpr1, stringExpr);
    s = v.verbalize(a);
    assertEquals("TRIE(\"string\" = Type1, anyVar, true, 4, true, 4, \"string\")", s);

    // UNMARK
    a = new UnmarkAction(typeExpr1, indexes, boolExpr1);
    s = v.verbalize(a);
    assertEquals("UNMARK(Type1, 4, numVar, true)", s);

    // UNMARKALL
    a = new UnmarkAllAction(typeExpr1, typeListExpr);
    s = v.verbalize(a);
    assertEquals("UNMARKALL(Type1, {Type1, typeVar})", s);

  }
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.