Ejemplo n.º 1
0
 private NLGElement processTypes(
     Map<String, Set<String>> typeMap, Set<String> vars, boolean count, boolean distinct) {
   List<NPPhraseSpec> objects = new ArrayList<NPPhraseSpec>();
   // process the type information to create the object(s)
   for (String s : typeMap.keySet()) {
     if (vars.contains(s)) {
       // contains the objects to the sentence
       NPPhraseSpec object;
       object = nlgFactory.createNounPhrase("?" + s);
       Set<String> types = typeMap.get(s);
       if (types.size() == 1) {
         NPPhraseSpec np = getNPPhrase(types.iterator().next(), true);
         if (distinct) {
           np.addModifier("distinct");
         }
         object.addPreModifier(np);
       } else {
         Iterator<String> typeIterator = types.iterator();
         String type0 = typeIterator.next();
         String type1 = typeIterator.next();
         NPPhraseSpec np0 = getNPPhrase(type0, true);
         //                        if (distinct) {
         //                            np0.addModifier("distinct");
         //                        }
         NPPhraseSpec np1 = getNPPhrase(type1, true);
         //                        if (distinct) {
         //                            np1.addModifier("distinct");
         //                        }
         CoordinatedPhraseElement cpe = nlgFactory.createCoordinatedPhrase(np0, np1);
         while (typeIterator.hasNext()) {
           NPPhraseSpec np = getNPPhrase(typeIterator.next(), true);
           //                        if (distinct) {
           //                            np.addModifier("distinct");
           //                        }
           cpe.addCoordinate(np);
         }
         cpe.setConjunction("as well as");
         if (distinct) {
           cpe.addPreModifier("distinct");
         }
         object.addPreModifier(cpe);
       }
       object.setFeature(Feature.CONJUNCTION, "or");
       objects.add(object);
     }
   }
   if (objects.size() == 1) {
     // if(count) objects.get(0).addPreModifier("the number of");
     return objects.get(0);
   } else {
     CoordinatedPhraseElement cpe =
         nlgFactory.createCoordinatedPhrase(objects.get(0), objects.get(1));
     if (objects.size() > 2) {
       for (int i = 2; i < objects.size(); i++) {
         cpe.addCoordinate(objects.get(i));
       }
     }
     // if(count) cpe.addPreModifier("the number of");
     return cpe;
   }
 }