Examples of AdjoiningPos


Examples of org.ictclas4j.bean.AdjoiningPos

        sn = snList.get(i);
        posList = sn.getAllPos();
        for (int j = 0; posList != null && j < posList.size(); j++) {
          double minFee = 1000000;
          int minPrev = 100000;
          AdjoiningPos pos = posList.get(j);
          SegNode psn = snList.get(i - 1);
          ArrayList<AdjoiningPos> pposList = psn.getAllPos();
          for (int k = 0; pposList != null && k < pposList.size(); k++) {
            double temp = -Math.log(context
                .getPossibility(0, pposList.get(k).getPos().getTag(), pos.getPos().getTag()));
            temp += pposList.get(k).getValue();// Add the fees
            if (temp < minFee) {
              minFee = temp;
              minPrev = k;
            }
          }
          pos.setPrev(minPrev);
          pos.setValue(pos.getValue() + minFee);
        }
      }
    }
  }
View Full Code Here

Examples of org.ictclas4j.bean.AdjoiningPos

                curWord = "��";
            }
          }

          if (sn.getPos() < 0) {
            AdjoiningPos pos = new AdjoiningPos( 0 , 0);
            sn.addPos(pos);
          } else {
            // ��unknownDict�ʵ���л�ȡ��ǰ�����д���
            SegAtom sa = unknownDict.getSegAtom(curWord, gbkID);
            for (int j = 0; sa != null && j < sa.getPosCount(); j++) {
              Pos pos = sa.getPos(j);
              double value = -Math.log((1 + pos.getFreq()));
              value += Math.log((context.getFreq(pos.getTag()) + sa.getPosCount() + 1));
              AdjoiningPos apos = new AdjoiningPos(pos , value);
              sn.addPos(apos);
            }

            if (Utility.SENTENCE_BEGIN.equals(curWord))
              sn.addPos(new AdjoiningPos( 100 , 0));

            else if (Utility.SENTENCE_END.equals(curWord))
              sn.addPos(new AdjoiningPos( 101 , 0));
            else {
              int freq = 0;
              sa = coreDict.getSegAtom(curWord, gbkID);
              if (sa != null) {
                double value = -Math.log((double) (1 + freq));
                value += Math.log((double) (context.getFreq(0) + sa.getPosCount()));
                sn.addPos(new AdjoiningPos( 0 , value));

              }
            }
          }
        } else {
          if (sn.getPos() > 0) {
            int tag = sn.getPos();
            double value = -Math.log(1 + sn.getFreq());
            value += Math.log(1 + context.getFreq(tag));
            if (value < 0)
              value = 0;
            sn.addPos(new AdjoiningPos( tag,  value));
          } else {
            if (sn.getPos() < 0) {
              sn.setPos(-sn.getPos());
              sn.addPos(new AdjoiningPos( -sn.getPos(),  sn.getFreq()));
            }
            SegAtom sa = coreDict.getSegAtom(curWord, gbkID);
            if (sa != null) {
              for (int j = 0; j < sa.getPosCount(); j++) {
                Pos pos = sa.getPos(j);
                double value = -Math.log(1 + pos.getFreq());
                value += Math.log(context.getFreq(pos.getTag()) + sa.getPosCount());
                sn.addPos(new AdjoiningPos(pos , value));
              }
            }
          }
        }

        if (sn.getAllPos() == null)
          guessPos(tagType, sn);

        // ���һ���ʽڵ��Ӧ��allPosΪnull����˵�����޷������ɴ�
        // ���Ĵ�������һ���ʵĴ���,���ǽ�����ʶ��ĩ##ĩ������
        if (i - 1 >= 0 && sns.get(i - 1).getPosSize() == -1) {
          if (sn.getPosSize() > 0) {
            Pos pos = sn.getAllPos().get(0).getPos();
            int ipos = pos.getTag() == POSTag.SEN_END ? POSTag.UNKNOWN : pos.getTag();
            AdjoiningPos apos = new AdjoiningPos( ipos , 0);
            sns.get(i - 1).addPos(apos);
          }
        }
      }

      // ���һ��������
      SegNode last = sns.get(i - 1);
      if (last != null) {
        SegNode sn = new SegNode();
        int tag = 0;
        if (tagType != Utility.TAG_TYPE.TT_NORMAL)
          tag = 101;
        else
          tag = 1;
        AdjoiningPos pos = new AdjoiningPos( tag, 0);
        sn.addPos(pos);
        sns.add(sn);
      }
    }
  }
View Full Code Here

Examples of org.ictclas4j.bean.AdjoiningPos

    if (sns != null && context != null) {
      for (int i = 0; i < sns.size(); i++) {
        if (i == 0) {
          int pos = tagType != Utility.TAG_TYPE.TT_NORMAL ? 100 : 0;
          prevAllPos = new ArrayList<AdjoiningPos>();
          prevAllPos.add(new AdjoiningPos(pos, 0));
        } else {
          prevAllPos = sns.get(i - 1).getAllPos();
        }
        allPos = sns.get(i).getAllPos();
        if (allPos != null)
          for (AdjoiningPos pos : allPos) {
            // �ҳ�ǰһ�����Ժ͵�ǰ�������п����ڽӵĴ���
            int bestPrev = 0;
            double minValue = 10000000;
            for (int k = 0; prevAllPos != null && k < prevAllPos.size(); k++) {
              AdjoiningPos prevPos = prevAllPos.get(k);
              double temp = context.computePossibility(prevPos.getPos().getTag(), pos.getPos().getTag());
              temp = -Math.log(temp) + prevPos.getValue();
              if (temp < minValue) {
                minValue = temp;
                bestPrev = k;
              }
            }
View Full Code Here

Examples of org.ictclas4j.bean.AdjoiningPos

      case TT_NORMAL:
        break;
      case TT_PERSON:
        if (word.indexOf("����") != -1) {
          freq = (double) 1 / (double) (context.getFreq(6) + 1);
          sn.addPos(new AdjoiningPos(6, freq));
        } else {
          freq = (double) 1 / (double) (context.getFreq(0) + 1);
          sn.addPos(new AdjoiningPos(0, freq));

          if (sn.getLen() >= 4) {
            freq = (double) 1 / (double) (context.getFreq(0) + 1);
            sn.addPos(new AdjoiningPos(0, freq));
            freq = (double) 1 / (double) (context.getFreq(11) * 8);
            sn.addPos(new AdjoiningPos(11, freq));
            freq = (double) 1 / (double) (context.getFreq(12) * 8);
            sn.addPos(new AdjoiningPos(12, freq));
            freq = (double) 1 / (double) (context.getFreq(13) * 8);
            sn.addPos(new AdjoiningPos(13, freq));
          } else if (sn.getLen() == 2) {
            freq = (double) 1 / (double) (context.getFreq(0) + 1);
            sn.addPos(new AdjoiningPos(0, freq));
            charType = Utility.charType(word);
            if (charType == Utility.CT_OTHER || charType == Utility.CT_CHINESE) {
              freq = (double) 1 / (double) (context.getFreq(1) + 1);
              sn.addPos(new AdjoiningPos(1, freq));
              freq = (double) 1 / (double) (context.getFreq(2) + 1);
              sn.addPos(new AdjoiningPos(2, freq));
              freq = (double) 1 / (double) (context.getFreq(3) + 1);
              sn.addPos(new AdjoiningPos(3, freq));
              freq = (double) 1 / (double) (context.getFreq(4) + 1);
              sn.addPos(new AdjoiningPos(4, freq));
            }
            freq = (double) 1 / (double) (context.getFreq(11) * 8);
            sn.addPos(new AdjoiningPos(11, freq));
            freq = (double) 1 / (double) (context.getFreq(12) * 8);
            sn.addPos(new AdjoiningPos(12, freq));
            freq = (double) 1 / (double) (context.getFreq(13) * 8);
            sn.addPos(new AdjoiningPos(13, freq));
          }
        }
        break;
      case TT_PLACE:
        freq = (double) 1 / (double) (context.getFreq(0) + 1);
        sn.addPos(new AdjoiningPos(0, freq));

        if (sn.getLen() >= 4) {
          freq = (double) 1 / (double) (context.getFreq(11) * 8);
          sn.addPos(new AdjoiningPos(11, freq));
          freq = (double) 1 / (double) (context.getFreq(12) * 8);
          sn.addPos(new AdjoiningPos(12, freq));
          freq = (double) 1 / (double) (context.getFreq(13) * 8);
          sn.addPos(new AdjoiningPos(13, freq));
        } else if (sn.getLen() == 2) {
          freq = (double) 1 / (double) (context.getFreq(0) + 1);
          sn.addPos(new AdjoiningPos(0, freq));
          charType = Utility.charType(word);
          if (charType == Utility.CT_OTHER || charType == Utility.CT_CHINESE) {

            freq = (double) 1 / (double) (context.getFreq(1) + 1);
            sn.addPos(new AdjoiningPos(1, freq));
            freq = (double) 1 / (double) (context.getFreq(2) + 1);
            sn.addPos(new AdjoiningPos(2, freq));
            freq = (double) 1 / (double) (context.getFreq(3) + 1);
            sn.addPos(new AdjoiningPos(3, freq));
            freq = (double) 1 / (double) (context.getFreq(4) + 1);
            sn.addPos(new AdjoiningPos(4, freq));
          }
          freq = (double) 1 / (double) (context.getFreq(11) * 8);
          sn.addPos(new AdjoiningPos(11, freq));
          freq = (double) 1 / (double) (context.getFreq(12) * 8);
          sn.addPos(new AdjoiningPos(12, freq));
          freq = (double) 1 / (double) (context.getFreq(13) * 8);
          sn.addPos(new AdjoiningPos(13, freq));
        }
        break;
      case TT_TRANS_PERSON:
        freq = (double) 1 / (double) (context.getFreq(0) + 1);
        sn.addPos(new AdjoiningPos(0, freq));
        if (!Utility.isAllChinese(word)) {
          if (Utility.isAllLetter(word)) {
            freq = (double) 1 / (double) (context.getFreq(1) + 1);
            sn.addPos(new AdjoiningPos(1, freq));
            freq = (double) 1 / (double) (context.getFreq(11) + 1);
            sn.addPos(new AdjoiningPos(11, freq));
            freq = (double) 1 / (double) (context.getFreq(2) * 2 + 1);
            sn.addPos(new AdjoiningPos(2, freq));
            freq = (double) 1 / (double) (context.getFreq(3) * 2 + 1);
            sn.addPos(new AdjoiningPos(3, freq));
            freq = (double) 1 / (double) (context.getFreq(12) * 2 + 1);
            sn.addPos(new AdjoiningPos(12, freq));
            freq = (double) 1 / (double) (context.getFreq(13) * 2 + 1);
            sn.addPos(new AdjoiningPos(13, freq));
          }
          freq = (double) 1 / (double) (context.getFreq(41) * 8);
          sn.addPos(new AdjoiningPos(41, freq));
          freq = (double) 1 / (double) (context.getFreq(42) * 8);
          sn.addPos(new AdjoiningPos(42, freq));
          freq = (double) 1 / (double) (context.getFreq(43) * 8);
          sn.addPos(new AdjoiningPos(43, freq));
        } else if (sn.getLen() >= 4) {
          freq = (double) 1 / (double) (context.getFreq(41) * 8);
          sn.addPos(new AdjoiningPos(41, freq));
          freq = (double) 1 / (double) (context.getFreq(42) * 8);
          sn.addPos(new AdjoiningPos(42, freq));
          freq = (double) 1 / (double) (context.getFreq(43) * 8);
          sn.addPos(new AdjoiningPos(43, freq));
        } else if (sn.getLen() == 2) {
          charType = Utility.charType(word);
          if (charType == Utility.CT_OTHER || charType == Utility.CT_CHINESE) {
            freq = (double) 1 / (double) (context.getFreq(1) * 2 + 1);
            sn.addPos(new AdjoiningPos(1, freq));
            freq = (double) 1 / (double) (context.getFreq(2) * 2 + 1);
            sn.addPos(new AdjoiningPos(2, freq));
            freq = (double) 1 / (double) (context.getFreq(3) * 2 + 1);
            sn.addPos(new AdjoiningPos(3, freq));
            freq = (double) 1 / (double) (context.getFreq(30) * 8 + 1);
            sn.addPos(new AdjoiningPos(30, freq));
            freq = (double) 1 / (double) (context.getFreq(11) * 4 + 1);
            sn.addPos(new AdjoiningPos(11, freq));
            freq = (double) 1 / (double) (context.getFreq(12) * 4 + 1);
            sn.addPos(new AdjoiningPos(12, freq));
            freq = (double) 1 / (double) (context.getFreq(13) * 4 + 1);
            sn.addPos(new AdjoiningPos(13, freq));
            freq = (double) 1 / (double) (context.getFreq(21) * 2 + 1);
            sn.addPos(new AdjoiningPos(21, freq));
            freq = (double) 1 / (double) (context.getFreq(22) * 2 + 1);
            sn.addPos(new AdjoiningPos(22, freq));
            freq = (double) 1 / (double) (context.getFreq(23) * 2 + 1);
            sn.addPos(new AdjoiningPos(23, freq));
          }
          freq = (double) 1 / (double) (context.getFreq(41) * 8);
          sn.addPos(new AdjoiningPos(41, freq));
          freq = (double) 1 / (double) (context.getFreq(42) * 8);
          sn.addPos(new AdjoiningPos(42, freq));
          freq = (double) 1 / (double) (context.getFreq(43) * 8);
          sn.addPos(new AdjoiningPos(43, freq));
        }
        break;
      default:
        break;
      }
View Full Code Here

Examples of org.ictclas4j.bean.AdjoiningPos

      // �����ǿ�ʼ�ͽ������
      for (int i = size - 1, j = 0; i >= 0; i--) {
        SegNode sn = sns.get(i);
        ArrayList<AdjoiningPos> allPos = sn.getAllPos();
        if (allPos != null && allPos.size() > j) {
          AdjoiningPos pos = allPos.get(j);
          pos.setBest(true);
          j = pos.getPrev();
        } else if (i + 1 < size - 1) {
          int tag = getBestTag(sns.get(i + 1));
          AdjoiningPos pos = new AdjoiningPos(tag, 0);
          pos.setBest(true);
          sns.get(i).addPos(pos);
        }
        // ����ô�����ĸ���֣��������û��������ҵʵ�������������øôʵĴ���
        if (sn.getPos() == POSTag.NOUN_LETTER || sn.getPos() == POSTag.NUM) {
          for (AdjoiningPos pos : allPos) {
            if (pos.isBest() && pos.getPos().getTag() > 0) {
              sn.setPos(pos.getPos().getTag());
              break;
            }
          }
        }
      }
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.