Examples of SegNode


Examples of org.ictclas4j.bean.SegNode

  private double computePossibility(int startPos, int length, ArrayList<SegNode> sns) {
    double retValue = 0, posPoss;

    if (sns != null && unknownDict != null && context != null) {
      for (int i = startPos; i < startPos + length && sns != null; i++) {
        SegNode sn = sns.get(i);
        int bestTag = getBestTag(sn);
        if (bestTag != -1) {
          int freq = unknownDict.getFreq(sn.getSrcWord(), bestTag);
          posPoss = Math.log((double) (context.getFreq(0, sn.getPos()) + 1));
          posPoss += -Math.log((double) (freq + 1));
          retValue += posPoss;
        }
      }
    }
View Full Code Here

Examples of org.ictclas4j.bean.SegNode

   * @param atoms
   * @return
   */
  public static SegGraph generate(ArrayList<Atom> atoms,Dictionary dict) {
    SegGraph segGraph = null;
    SegNode sn = null;
    Atom atom = null;

    if (atoms != null && atoms.size() > 0 && dict != null) {
      segGraph = new SegGraph();
      for (int i = 0; i < atoms.size(); i++) {
        atom = atoms.get(i);
        String word = atom.getWord();
        if (atom.getPos() == Utility.CT_CHINESE)
          sn = new SegNode(i, i + 1, 0,0, atom.getWord());
        else {
          double value = Utility.MAX_FREQUENCE;
          int pos = 0;

          switch (atom.getPos()) {
          case Utility.CT_INDEX:
          case Utility.CT_NUM:
            pos = -POSTag.NUM;// 'm'*256
            word = Utility.UNKNOWN_NUM;
            value = 0;
            break;
          case Utility.CT_DELIMITER:
            pos = POSTag.PUNC;// 'w'*256;
            break;
          case Utility.CT_LETTER:
            pos = -POSTag.NOUN_LETTER;//
            value = 0;
            word = Utility.UNKNOWN_LETTER;
            break;
          case Utility.CT_SINGLE:// 12021-2129-3121
            if (Utility.getCharCount("+-1234567890", atom.getWord()) == atom.getLen()) {
              pos = -POSTag.NUM;// 'm'*256
              word = Utility.UNKNOWN_NUM;
            } else {
              pos = -POSTag.NOUN_LETTER;//
              word = Utility.UNKNOWN_LETTER;
            }
            value = 0;
            break;
          default:
            pos = atom.getPos();// '?'*256;
            break;
          }

          sn = new SegNode(i, i + 1,pos, value , word);
        }

        sn.setSrcWord(atom.getWord());
        segGraph.insert(sn, true);
      }

      String word = null;
      for (int i = 0; i < atoms.size(); i++) {
        int j = i + 1;
        word = atoms.get(i).getWord();
        // ����ǡ��·ݡ�����Ҫ�ָ�
        boolean flag = false;
        if (j < atoms.size()) {
          Atom a2 = atoms.get(j);
          if ("��".equals(word) && "��".equals(a2.getWord())) {
            segGraph.delete(i, j);
            segGraph.delete(i + 1, j + 1);
            word += a2.getWord();
            flag = true;
            j++;
          }
        }

        WordItem wi = null;
        for (; j <= atoms.size(); j++) {
          int totalFreq = 0;
          wi = dict.getMaxMatch(word);
          if (wi != null) {
            // find it
            if (word.equals(wi.getWord())) {
              ArrayList<WordItem> wis = dict.getHandle(word);
              for (WordItem w : wis)
                totalFreq += w.getFreq();

              // 1���ڣ�1999��ĩ
              if (word.length() == 2 && segGraph.getSize() > 0) {
                SegNode g2 = segGraph.getLast();
                if (Utility.isAllNum(g2.getWord()) || Utility.isAllChinese(g2.getWord())
                    && (g2.getWord().indexOf("��") == 0 || g2.getWord().indexOf("��") == 0)) {

                  if ("ĩ���е�ǰ���".indexOf(word.substring(1)) != -1)
                    break;
                }
              }
              // ֻ��һ���Դʣ�������
              SegNode sg = null;
              if (wis.size() == 1)
                sg = new SegNode(i, j,wis.get(0).getHandle(),totalFreq , word);
              else
                sg = new SegNode(i, j, 0,totalFreq , word);
           
              segGraph.insert(sg, true);

            }
            if (flag)
View Full Code Here

Examples of org.ictclas4j.bean.SegNode

    if (seg != null && dict != null && biDict != null) {
      segGraph = new SegGraph();
      ArrayList<SegNode> sgs = seg.getSnList();

      for (int i = 0; sgs != null && i < sgs.size(); i++) {
        SegNode sg = sgs.get(i);
        if (sg.getPos() >= 0)
          curFreq = sg.getValue();
        else
          curFreq = dict.getFreq(sg.getWord(), 2);

        // �õ�������ֵ�͸���ֵ��ȵ�����Ԫ��
        ArrayList<SegNode> nextSgs = seg.getNextElements(i);
        for (SegNode graph : nextSgs) {
          String twoWords = sg.getWord();
          twoWords += Utility.WORD_SEGMENTER;
          twoWords += graph.getWord();

          // ��������������֮���ƽ��ֵ
          // -log{a*P(Ci-1)+(1-a)P(Ci|Ci-1)} Note 0<a<1
          int twoFreq = biDict.getFreq(twoWords, 3);
          double temp = (double) 1 / Utility.MAX_FREQUENCE;
          double value = smoothParam * (1 + curFreq) / (Utility.MAX_FREQUENCE + 80000);
          value += (1 - smoothParam) * ((1 - temp) * twoFreq / (1 + curFreq) + temp);
          value = -Math.log(value);

          if (value < 0)
            value += sg.getValue();

          SegNode sg2 = new SegNode();
          // �ָ���@ǰ�Ĵ��������е�λ��
          int wordIndex = getWordIndex(sgs, sg);
          sg2.setRow(wordIndex);

          // �ָ���@��Ĵ��������е�λ��
          wordIndex = getWordIndex(sgs, graph);
          sg2.setCol(wordIndex);
          sg2.setWord(twoWords);
          sg2.setPos(sg.getPos());
          sg2.setValue(value);
          segGraph.insert(sg2, false);
        }
      }
    }
    return segGraph;
View Full Code Here

Examples of org.ictclas4j.bean.SegNode

  public SegGraph(ArrayList<SegNode> snList) {
    this.snList = snList;
  }

  public SegNode getElement(int row, int col) {
    SegNode result = new SegNode();
    result.setValueUtility.INFINITE_VALUE );
    // if (row > m_nRow || col > m_nCol)
    // return null;

    int index = 0;
    if (snList != null) {
      if (isRowFirst) {
        for (int i = 0; i < snList.size(); i++, index++) {
          SegNode sg = snList.get(i);
          if (row != -1 && sg.getRow() < row || col != -1 && sg.getRow() == row && sg.getCol() < col)
            continue;
          else
            break;
        }
      } else {
        for (int i = 0; i < snList.size(); i++, index++) {
          SegNode sg = snList.get(i);
          if (col != -1 && sg.getCol() < col || row != -1 && sg.getCol() == col && sg.getRow() < row)
            continue;
          else
            break;
        }
      }

      // Find it and return the value
      if (index < snList.size()) {
        SegNode sg = snList.get(index);
        if ((sg.getRow() == row || row == -1) && (sg.getCol() == col || col == -1))
          result = sg;
      }
    }
    return result;
View Full Code Here

Examples of org.ictclas4j.bean.SegNode

    if (sg != null) {
      if (snList == null)
        snList = new ArrayList<SegNode>();

      int i = 0;
      SegNode sgTemp = null;
      if (isRowFirst) {
        for (i = 0; i < snList.size(); i++) {
          sgTemp = snList.get(i);
          if (sgTemp.getRow() < sg.getRow() || sgTemp.getRow() == sg.getRow()
              && sgTemp.getCol() < sg.getCol())
            continue;
          else
            break;
        }
      } else {
        for (i = 0; i < snList.size(); i++) {
          sgTemp = snList.get(i);
          if (sgTemp.getCol() < sg.getCol() || sgTemp.getCol() == sg.getCol()
              && sgTemp.getRow() < sg.getRow())
            continue;
          else
            break;
        }
      }

      if (sgTemp != null && sgTemp.getRow() == sg.getRow() && sgTemp.getCol() == sg.getCol())
        sgTemp = sg;
      else if (i > 0)
        snList.add(i - 1, sg);

    }
View Full Code Here

Examples of org.ictclas4j.bean.SegNode

    ArrayList<SegNode> result = null;

    if (snList != null && snList.size() > 0 && curIndex >= 0) {
      result = new ArrayList<SegNode>();
      for (int i = 0; i < snList.size(); i++) {
        SegNode sg = snList.get(i);
        if (isColFirst) {
          if (sg.getCol() == curIndex)
            result.add(sg);
        } else {
          if (sg.getRow() == curIndex)
            result.add(sg);
        }

      }
    }
View Full Code Here

Examples of org.ictclas4j.bean.SegNode

   * @param isRowFirst
   *            �Ƿ�������ԭ��
   * @return �������ɹ�����True,���򷵻�False
   */
  public boolean insert(SegNode graph, boolean isRowFirst) {
    SegNode sg = null;
    if (snList == null)
      snList = new ArrayList<SegNode>();

    if (graph != null) {
      if (snList.size() == 0) {
        snList.add(graph);
        return true;
      }

      for (int i = 0; i < snList.size(); i++) {
        sg = snList.get(i);

        if (isRowFirst) {
          // �����һ���ڵ�
          if (i == snList.size() - 1) {
            if (graph.getRow() > sg.getRow()
                || (graph.getRow() == sg.getRow() && graph.getCol() > sg.getCol()))
              snList.add(graph);
            else {
              if (graph.getCol() == sg.getCol()) {
                snList.set(i, graph);
              } else
                snList.add(i, graph);
            }
            return true;
          }

          if (graph.getRow() > sg.getRow() || (graph.getRow() == sg.getRow() && graph.getCol() > sg.getCol()))
            continue;
          else {
            if (graph.getRow()==sg.getRow() && graph.getCol() == sg.getCol()) {
              snList.set(i, graph);
            } else
              snList.add(i, graph);

            return true;
          }
        } else {
          // �����һ���ڵ�
          if (i == snList.size() - 1) {
            if (graph.getCol() > sg.getCol()
                || (graph.getCol() == sg.getCol() && graph.getRow() > sg.getRow()))
              snList.add(graph);
            else {
              if (graph.getRow()==sg.getRow() && graph.getCol() == sg.getCol()) {
                snList.set(i, graph);
              } else
                snList.add(i, graph);
            }
            return true;
          }

          if (graph.getCol() > sg.getCol() || (graph.getCol() == sg.getCol() && graph.getRow() > sg.getRow()))
            continue;
          else {
            if (graph.getRow() == sg.getRow()) {
              snList.set(i, graph);
            } else
              snList.add(i, graph);

            return true;
View Full Code Here

Examples of org.ictclas4j.bean.SegNode

    return false;
  }

  public SegNode delete(int row, int col) {
    SegNode result = null;

    if (snList != null && snList.size() > 0) {
      for (SegNode sn : snList) {
        if (sn.getRow() == row && sn.getCol() == col) {
          snList.remove(sn);
View Full Code Here

Examples of org.ictclas4j.bean.SegNode

  public ArrayList<SegNode> getNextElements(int curIndex) {
    ArrayList<SegNode> result = null;

    if (snList != null && snList.size() > 0 && curIndex >= 0 && curIndex < snList.size()) {
      result = new ArrayList<SegNode>();
      SegNode curSg = snList.get(curIndex);

      for (int i = curIndex + 1; i < snList.size(); i++) {
        SegNode sg = snList.get(i);
        if (sg.getRow() == curSg.getCol())
          result.add(sg);

      }
    }
    return result;
View Full Code Here

Examples of org.ictclas4j.bean.SegNode

  public int getMaxRow() {
    int result = -1;

    if (snList != null && snList.size() > 0) {
      int size = snList.size();
      SegNode sn = snList.get(size - 1);
      result = sn.getRow();
    }

    return result;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.