public double getValue(Document doc) throws EventGenerationException {
   double wordCount = wordCounter.getValue(doc);
   double sentenceCount = sentenceCounter.getValue(doc);
   EventSet syllables = syllablesDriver.createEventSet(doc);
   for (int i = syllables.size() - 1; i >= 0; i--) {
     if (Integer.parseInt(syllables.eventAt(i).toString()) < 3) {
       syllables.removeEvent(syllables.eventAt(i));
     }
   }
   double complexWordsCount = syllables.size();
   return 0.4 * (wordCount / sentenceCount + 100 * complexWordsCount / wordCount);
 }
예제 #2
0
 @Override
 public EventSet createEventSet(char[] text) throws EventGenerationException {
   return truncate(theDriver.createEventSet(text), length);
 }
예제 #3
0
 public int compareTo(EventDriver o) {
   return displayName().compareTo(o.displayName());
 }
예제 #4
0
  @Override
  public EventSet createEventSet(Document ds) throws EventGenerationException {
    String param;
    HashMap<String, String> transform = new HashMap<String, String>();
    boolean whitelist = false;

    String line;
    String[] words;

    if (!(param = (getParameter("underlyingEvents"))).equals("")) {
      try {
        underlyingEvents = EventDriverFactory.getEventDriver(param);
      } catch (Exception e) {
        System.out.println("Error: cannot create EventDriver " + param);
        System.out.println(" -- Using NaiveWordEventSet");
        underlyingEvents = new NaiveWordEventDriver();
      }
    } else { // no underlyingEventsParameter, use NaiveWordEventSet
      underlyingEvents = new NaiveWordEventDriver();
    }

    if (!(param = (getParameter("filename"))).equals("")) {
      filename = param;
    } else { // no underlyingfilename,
      filename = null;
    }

    if (!(param = (getParameter("implicitWhiteList"))).equals("")) {
      if (param.equalsIgnoreCase("true")) {
        whitelist = true;
      }
    } else { // no underlyingfilename,
      whitelist = false;
    }

    EventSet es = underlyingEvents.createEventSet(ds);

    EventSet newEs = new EventSet();
    newEs.setAuthor(es.getAuthor());
    newEs.setNewEventSetID(es.getAuthor());

    BufferedReader br = null;

    if (filename != null) {
      try {
        FileInputStream fis = new FileInputStream(filename);
        br = new BufferedReader(new InputStreamReader(fis));

        while ((line = br.readLine()) != null) {
          if (line.length() > 0) {
            String sep = line.substring(0, 1);
            words = line.substring(1).split(sep, -1);
            if (words.length > 1) {
              transform.put(words[0], words[1]);
              System.out.println("Adding \"" + words[0] + "\" : \"" + words[1] + "\"");
            }
          }
        }

      } catch (IOException e) {
        // catch io errors from FileInputStream or readLine()
        System.out.println("Cannot open/read " + filename);
        System.out.println("IOException error! " + e.getMessage());
        transform = null;
      } finally {
        // if the file opened okay, make sure we close it
        if (br != null) {
          try {
            br.close();
          } catch (IOException ioe) {
          }
        }
      }
    } else {
      transform = null;
    }

    for (Event e : es) {
      String s = e.toString();
      if (transform == null) {
        newEs.addEvent(e);
      } else if (transform.containsKey(s)) {
        String newS = transform.get(s);
        if (newS.length() > 0) {
          newEs.addEvent(new Event(newS));
        }
      } else // s is not in transformation list
      if (whitelist == false) {
        // add only if no implicit whitelisting
        newEs.addEvent(e);
      } // otherwise add nothing
    }
    return newEs;
  }