Package org.fnlp.nlp.parser

Examples of org.fnlp.nlp.parser.Sentence


    LabelAlphabet postagAlphabet = factory.buildLabelAlphabet("postag");

    int count = 0;
    while (reader.hasNext()) {

      Sentence instance = (Sentence) reader.next();
      int[] heads = (int[]) instance.getTarget();
      ParsingState state = new ParsingState(instance,factory);
      while (!state.isFinalState()) {
        // 左右焦点词在句子中的位置
        int[] lr = state.getFocusIndices();

        HashSparseVector features = state.getFeatures();
        ParsingState.Action action = getAction(lr[0], lr[1],
            heads);
        state.next(action);
        if (action == ParsingState.Action.LEFT)
          heads[lr[1]] = -1;
        if (action == ParsingState.Action.RIGHT)
          heads[lr[0]] = -1;

        // writer.write(String.valueOf(instance.postags[lr[0]]));
        String pos = instance.getTagAt(lr[0]);
        postagAlphabet.lookupIndex(pos);
        writer.write(pos);
        writer.write(" ");
        switch (action) {
        case LEFT:
View Full Code Here


    int count = 0;
   
    //preReader为了把ysize定下来
    la.lookupIndex("S");
    while(preReader.hasNext()){
      Sentence sent = (Sentence) preReader.next();
      Target targets = (Target)sent.getTarget();
      for(int i=0; i<sent.length(); i++){
        String label;
        if(targets.getHead(i) != -1){
          if(targets.getHead(i) < i){
            label = "L" + targets.getDepClass(i);
          }
          //else if(targets.getHead(i) > i){
          else{
            label = "R" + targets.getDepClass(i);
          }
          la.lookupIndex(label);
        }
      }
    }
    int ysize = la.size();
    la.setStopIncrement(true);
       
    while (reader.hasNext()) {
      Sentence sent = (Sentence) reader.next();
      //  int[] heads = (int[]) instance.getTarget();
      String depClass = null;
      Target targets = (Target)sent.getTarget();
      JointParsingState state = new JointParsingState(sent);
     
      while (!state.isFinalState()) {
        // 左右焦点词在句子中的位置
        int[] lr = state.getFocusIndices();

        ArrayList<String> features = state.getFeatures();
        JointParsingState.Action action = getAction(lr[0], lr[1],
            targets);
        switch (action) {
        case LEFT:
          depClass = targets.getDepClass(lr[1]);
          break;
        case RIGHT:
          depClass = targets.getDepClass(lr[0]);
          break;
        default:

        }
        state.next(action,depClass);
        if (action == JointParsingState.Action.LEFT)
          targets.setHeads(lr[1],-1);
        if (action == JointParsingState.Action.RIGHT)
          targets.setHeads(lr[0],-1);
        String label = "";
        switch (action) {
        case LEFT:
          label += "L"+sent.getDepClass(lr[1]);   
          break;
        case RIGHT:
          label+="R"+sent.getDepClass(lr[0]);
          break;
        default:
          label = "S";         
        }
        int id = la.lookupIndex(label);       
View Full Code Here

      writer = new BufferedWriter(new OutputStreamWriter(
          new FileOutputStream(resultFile), charset));

    long beginTime = System.currentTimeMillis();
    while (reader.hasNext()) {
      Sentence instance = (Sentence) reader.next();
      // int[] golds = new int[instance.length()];
      int[] heads = (int[]) instance.getTarget();
      // System.arraycopy(heads, 0, golds, 0, golds.length);
      // instance.setSource(heads);

      Predict<int[]> pred = parser.getBest(instance);
View Full Code Here

    long beginTime = System.currentTimeMillis();
    int count = 0;
    while (reader.hasNext()) {
//      System.out.println(count++);
      Sentence instance = (Sentence) reader.next();
     
      Target targets = (Target) instance.getTarget();

      int[] heads = targets.getHeads();     
      String[] depClass = targets.getRelations();
      Target t = parser.parse2R(instance);     
      String[] dPreds = (String[]) t.getRelations();
View Full Code Here

    IFeatureAlphabet features = factory.DefaultFeatureAlphabet();
    features.setStopIncrement(true);
  }

  public Predict<int[]> getBest(Instance inst) {
    Sentence sent = (Sentence) inst;

    Predict<DependencyTree> res = _getBestParse(sent);
    float score = res.getScore(0);
    DependencyTree dt = res.getLabel(0);
   
    Predict<int[]> ret = new Predict<int[]>();
    int[] preds = new int[sent.length()];
    Arrays.fill(preds, -1);
    DependencyTree.toArrays(dt, preds);
    ret.add(preds,score);
    return ret;
  }
View Full Code Here

//  public int[] parse(String[][] strings) {
//    return parse(new Sentence(strings));
//  }
 
  public int[] parse(String[] words, String[] pos)  {
    return parse(new Sentence(words, pos));
  }
View Full Code Here

  public DependencyTree getBestParse(String[] words)  {
    return getBestParse(words, null);
  }
 
  public DependencyTree getBestParse(String[] words, String[] tags)  {
    return getBestParse(new Sentence(words, tags));
  }
View Full Code Here

    return result;
  }

  public Target jointParse(Instance inst)  {
    Sentence sent = (Sentence) inst;

    Predict<DependencyTree> res = _getBestParse(sent);
    DependencyTree dt = res.getLabel(0);

    Target target = new Target(sent.length());

    target=target.ValueOf(dt);

    return target;
  }
View Full Code Here

//  public int[] parse(String[][] strings) {
//    return parse(new Sentence(strings));
//  }

  public int[] parse(String[] words, String[] pos)  {
    return parse(new Sentence(words, pos));
  }
View Full Code Here

  public int[] parse(String[] words, String[] pos)  {
    return parse(new Sentence(words, pos));
  }
 
  public Predict<int[]> getBest(Instance inst) {
    Sentence sent = (Sentence) inst;

    Predict<DependencyTree> res = _getBestParse(sent);
    float score = res.getScore(0);
    DependencyTree dt = res.getLabel(0);

    Predict<int[]> ret = new Predict<int[]>();
    int[] preds = new int[sent.length()];
    Arrays.fill(preds, -1);
    DependencyTree.toArrays(dt, preds);
    ret.add(preds,score);
    return ret;
  }
View Full Code Here

TOP

Related Classes of org.fnlp.nlp.parser.Sentence

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.