Examples of SegResult


Examples of org.ictclas4j.bean.SegResult

    this.segPathCount = segPathCount;
    this.isRecogniseUnknown = true;
  }

  public SegResult split(String src) {
    SegResult finalResult = new SegResult();// �ִʽ��
    DebugResult debugResult = new DebugResult(src);

    if (src != null) {
      int index = 0;
      SegResult midResult = null;
      finalResult.setRawContent(src);
      SentenceSeg ss = new SentenceSeg(src);
      ArrayList<Sentence> sens = ss.getSens();

      for (Sentence sen : sens) {
        logger.debug(sen);
        MidResult mr = new MidResult();
        mr.setIndex(index++);
        mr.setSource(sen.getContent());
        if (sen.isSeg()) {

          // ԭ�ӷִ�
          AtomSeg as = new AtomSeg(sen.getContent());
          ArrayList<Atom> atoms = as.getAtoms();
          mr.setAtoms(atoms);

          // ���ɷִ�ͼ��,�Ƚ��г����ִʣ�Ȼ������Ż��������д��Ա��
          SegGraph segGraph = GraphGenerate.generate(atoms, dictLib);
          mr.setSegGraph(segGraph.getSnList());
          // ���ɶ���ִ�ͼ��
          SegGraph biSegGraph = GraphGenerate.biGenerate(segGraph, dictLib);
          mr.setBiSegGraph(biSegGraph.getSnList());

          // ��N���·��
          NShortPath nsp = new NShortPath(biSegGraph, segPathCount);
          ArrayList<ArrayList<Integer>> bipath = nsp.getPaths();
          mr.setBipath(bipath);

          for (ArrayList<Integer> onePath : bipath) {
            // �õ����ηִ�·��
            ArrayList<SegNode> segPath = getSegPath(segGraph, onePath);
            ArrayList<SegNode> firstPath = AdjustSeg.firstAdjust(segPath);
            SegResult firstResult = outputResult(firstPath);
            mr.addFirstResult(firstResult.toString());

            if (isRecogniseUnknown)
              midResult = optinium(mr, firstPath);
            else {
              PosTagger lexTagger = new PosTagger(Utility.TAG_TYPE.TT_NORMAL, dictLib);
              lexTagger.recognise(firstPath);
              SegResult optResult = outputResult(firstPath);
              mr.addOptResult(optResult.toString());
              ArrayList<SegNode> adjResult = AdjustSeg.finalAdjust(firstPath, dictLib);

              midResult = outputResult(adjResult);
            }
            break;
          }
        } else {
          SegAtom atom = new SegAtom(sen.getContent());
          SegAtom[] atoms = new SegAtom[1];
          atoms[0] = atom;
          midResult = new SegResult();
          midResult.setRawContent(sen.getContent());
          midResult.setAtoms(atoms);
        }
        finalResult.merge(midResult);
        debugResult.addMidResult(mr);
View Full Code Here

Examples of org.ictclas4j.bean.SegResult

    return finalResult;
  }

  // �Գ��ηִʽ�������Ż�
  private SegResult optinium(MidResult mr, ArrayList<SegNode> firstPath) {
    SegResult result = null;
    if (mr != null && firstPath != null) {
      // ����δ��½�ʣ����Գ��ηִʽ�������Ż�
      SegGraph optSegGraph = new SegGraph(firstPath);
      ArrayList<SegNode> sns = clone(firstPath);
      PosTagger personTagger = new PosTagger(Utility.TAG_TYPE.TT_PERSON, dictLib);
      personTagger.recognise(optSegGraph, sns);
      PosTagger transPersonTagger = new PosTagger(Utility.TAG_TYPE.TT_TRANS_PERSON, dictLib);
      transPersonTagger.recognise(optSegGraph, sns);
      // PosTagger placeTagger=new
      // PosTagger(Utility.TAG_TYPE.TT_PLACE,dictLib);
      // placeTagger.recognise(optSegGraph, sns);
      mr.setOptSegGraph(optSegGraph.getSnList());

      // �����Ż���Ľ�������½������ɶ���ִ�ͼ��
      SegGraph optBiSegGraph = GraphGenerate.biGenerate(optSegGraph, dictLib);
      mr.setOptBiSegGraph(optBiSegGraph.getSnList());

      // ������ȡN�����·��
      NShortPath optNsp = new NShortPath(optBiSegGraph, segPathCount);
      ArrayList<ArrayList<Integer>> optBipath = optNsp.getPaths();
      mr.setOptBipath(optBipath);

      // �����Ż���ķִʽ�������Խ�����д��Ա�Ǻ������Ż���������
      ArrayList<SegNode> adjResult = null;
      PosTagger lexTagger = new PosTagger(Utility.TAG_TYPE.TT_NORMAL, dictLib);
      for (ArrayList<Integer> optOnePath : optBipath) {
        ArrayList<SegNode> optSegPath = getSegPath(optSegGraph, optOnePath);
        lexTagger.recognise(optSegPath);
        SegResult optResult = outputResult(optSegPath);
        mr.addOptResult(optResult.toString());
        adjResult = AdjustSeg.finalAdjust(optSegPath, dictLib);
        result = outputResult(adjResult);
        break;
      }
    }
View Full Code Here

Examples of org.ictclas4j.bean.SegResult

    return path;
  }

  // ���ݷִ�·�����ɷִʽ��
  private SegResult outputResult(ArrayList<SegNode> wrList) {
    SegResult result = null;
    if (wrList != null && wrList.size() > 0) {
      result = new SegResult();
      ArrayList<SegAtom> saList = new ArrayList<SegAtom>();
      for (int i = 0; i < wrList.size(); i++) {

        SegNode sn = wrList.get(i);
        if (sn.getPos() != POSTag.SEN_BEGIN && sn.getPos() != POSTag.SEN_END) {
          SegAtom sa =sn.toSegAtom();
          saList.add(sa);
        }
      }

      SegAtom[] atoms = new SegAtom[saList.size() - 1];
      atoms = saList.toArray(atoms);
      result.setAtoms(atoms);
    }

    return result;
  }
View Full Code Here

Examples of org.ictclas4j.bean.SegResult

          int segPathCount = Integer.parseInt(jtSegPathCount.getText());
          DictLib dictLib=SegMain.dictLib;
          Segment seg=new Segment(dictLib,segPathCount);
          seg.setOutputMidResult(true);
          seg.setRecogniseUnknown(true);
          SegResult sr = seg.split(jtSrcMsg.getText());
          jtSplitMsg.setText( sr.toString());
        }
      });
    }
    return jbSplitOK;
  }
View Full Code Here

Examples of org.ictclas4j.bean.SegResult

            ArrayList<String> testCases = GFFile.readTxtFile2("test"+GFFinal.FILE_SEP+"case1.txt");
           
            long times=System.currentTimeMillis();
            for (int i = 0; i < forCount; i++) {
              for (String src : testCases) {
                SegResult sr =seg.split(src);
                bytes += src.getBytes().length;
                jtSplitMsg.setText(sr.toString());
              }
            }
           
            times=System.currentTimeMillis()-times;
            System.out.println("times:"+times+"ms"+",bytes:"+bytes+",avg:"+(bytes/times)+"kb/s");
View Full Code Here

Examples of org.ictclas4j.bean.SegResult

  private void segRequest(byte[] bs) {
    if (bs != null && out != null) {
      SegRequest req = new SegRequest(bs);
      String content = req.getContent();
      SegResult sr = getSeg(content);

      try {
        MsgPack pack = new MsgPack(CmdID.SEG_RESPONSE, sr);
        out.write(pack.getBytes());
        out.flush();
View Full Code Here

Examples of org.ictclas4j.bean.SegResult

    }
  }

  private SegResult getSeg(String content) {
    SegResult result = null;

    // first, read from cache
    result = dictLib.getCachedSeg(content);
    // then,segment factly
    if (result == null) {
View Full Code Here

Examples of org.ictclas4j.bean.SegResult

      jbSplitOK.setText("�ִ�");
      jbSplitOK.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent e) {
          int segPathCount = Integer.parseInt(jtSegPathCount.getText());
          SegMain.seg.setSegPathCount(segPathCount);
          SegResult sr = SegMain.seg.split(jtSrcMsg.getText());
          jtSplitMsg.setText("[Time:" + sr.getSpendTime() + "ms]:\n" + sr.getFinalResult());
        }
      });
    }
    return jbSplitOK;
  }
View Full Code Here

Examples of org.ictclas4j.bean.SegResult

            SegMain.seg.setSegPathCount(segPathCount);
            int forCount=Integer.parseInt(jtFor.getText());
            ArrayList<String> testCases = readTxtFile2("test\\case1.txt");
            for (int i = 0; i < forCount; i++) {
              for (String src : testCases) {
                SegResult sr = SegMain.seg.split(src);
                count++;
                bytes+=src.getBytes().length;
                times+=sr.getSpendTime();
                jtSrcMsg.setText("total_count:"+count+"\ntotal_time:"+times+"\ntotal_bytes:"+bytes
                    +"\navg_time:"+(times/count)+"\navg_bytes:"+(bytes/times)+"b/ms");
                jtSplitMsg.setText("[time:" + sr.getSpendTime() + "ms]:\n" + sr.getFinalResult());
              }
            }
          } catch (IOException e1) {
            e1.printStackTrace();
          }
View Full Code Here

Examples of org.ictclas4j.bean.SegResult

    lexTagger = new PosTagger(Utility.TAG_TYPE.TT_NORMAL, "data\\lexical", coreDict);
    logger.info("Load dict is over");
  }

  public SegResult split(String src) {
    SegResult sr = new SegResult(src);// �ִʽ��
    String finalResult = null;

    if (src != null) {
      finalResult = "";
      int index = 0;
      String midResult = null;
      sr.setRawContent(src);
      SentenceSeg ss = new SentenceSeg(src);
      ArrayList<Sentence> sens = ss.getSens();
      for (Sentence sen : sens) {
        logger.debug(sen);
        MidResult mr = new MidResult();
        mr.setIndex(index++);
        mr.setSource(sen.getContent());
        if (sen.isSeg()) {

          // ԭ�ӷִ�
          AtomSeg as = new AtomSeg(sen.getContent());
          ArrayList<Atom> atoms = as.getAtoms();
          mr.setAtoms(atoms);

          // ���ɷִ�ͼ��,�Ƚ��г����ִʣ�Ȼ������Ż��������д��Ա��
          SegGraph segGraph = GraphGenerate.generate(atoms, coreDict);
          mr.setSegGraph(segGraph.getSnList());
          // ���ɶ���ִ�ͼ��
          SegGraph biSegGraph = GraphGenerate.biGenerate(segGraph, coreDict, bigramDict);
          mr.setBiSegGraph(biSegGraph.getSnList());
          // ��N���·��
          NShortPath nsp = new NShortPath(biSegGraph, segPathCount);
          ArrayList<ArrayList<Integer>> bipath = nsp.getPaths();
          mr.setBipath(bipath);

          for (ArrayList<Integer> onePath : bipath) {
            // �õ����ηִ�·��
            ArrayList<SegNode> segPath = getSegPath(segGraph, onePath);
            ArrayList<SegNode> firstPath = AdjustSeg.firstAdjust(segPath);
            String firstResult = outputResult(firstPath);
            mr.addFirstResult(firstResult);

            // ����δ��½�ʣ����Գ��ηִʽ�������Ż�
            SegGraph optSegGraph = new SegGraph(firstPath);
            ArrayList<SegNode> sns = clone(firstPath);
            personTagger.recognition(optSegGraph, sns);
            transPersonTagger.recognition(optSegGraph, sns);
            placeTagger.recognition(optSegGraph, sns);
            mr.setOptSegGraph(optSegGraph.getSnList());

            // �����Ż���Ľ�������½������ɶ���ִ�ͼ��
            SegGraph optBiSegGraph = GraphGenerate.biGenerate(optSegGraph, coreDict, bigramDict);
            mr.setOptBiSegGraph(optBiSegGraph.getSnList());

            // ������ȡN�����·��
            NShortPath optNsp = new NShortPath(optBiSegGraph, segPathCount);
            ArrayList<ArrayList<Integer>> optBipath = optNsp.getPaths();
            mr.setOptBipath(optBipath);

            // �����Ż���ķִʽ�������Խ�����д��Ա�Ǻ������Ż���������
            ArrayList<SegNode> adjResult = null;
            for (ArrayList<Integer> optOnePath : optBipath) {
              ArrayList<SegNode> optSegPath = getSegPath(optSegGraph, optOnePath);
              lexTagger.recognition(optSegPath);
              String optResult = outputResult(optSegPath);
              mr.addOptResult(optResult);
              adjResult = AdjustSeg.finaAdjust(optSegPath, personTagger, placeTagger);
              String adjrs = outputResult(adjResult);
              if (midResult == null)
                midResult = adjrs;
              break;
            }
          }
          sr.addMidResult(mr);
        } else
          midResult = sen.getContent();
        finalResult += midResult;
        midResult = null;
      }

      sr.setFinalResult(finalResult);
      DebugUtil.output2html(sr);
      logger.info(finalResult);
    }

    return sr;
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.