Example #1
0
        /**
         * 一句话调用接口
         *
         * @param document 目标文档
         * @param size     需要的关键句的个数
         * @return 关键句列表
         */
        public static List <String> getTopSentenceList(String document, int size)
        {
            List <String>         sentenceList = spiltSentence(document);
            List <List <String> > docs         = convertSentenceListToDocument(sentenceList);
            TextRankSentence      textRank     = new TextRankSentence(docs);

            int[]         topSentence = textRank.getTopSentence(size);
            List <String> resultList  = new List <String>();

            foreach (int i in topSentence)
            {
                resultList.Add(sentenceList[i]);
            }
            return(resultList);
        }
Example #2
0
        /**
         * 一句话调用接口
         *
         * @param document   目标文档
         * @param max_length 需要摘要的长度
         * @return 摘要文本
         */
        public static String getSummary(String document, int max_length)
        {
            List <String> sentenceList = spiltSentence(document);

            int sentence_count      = sentenceList.Count;
            int document_length     = document.Length;
            int sentence_length_avg = document_length / sentence_count;
            int size = max_length / sentence_length_avg + 1;
            List <List <String> > docs     = convertSentenceListToDocument(sentenceList);
            TextRankSentence      textRank = new TextRankSentence(docs);

            int[]         topSentence = textRank.getTopSentence(size);
            List <String> resultList  = new List <String>();

            foreach (int i in topSentence)
            {
                resultList.Add(sentenceList[i]);
            }

            resultList = permutation(resultList, sentenceList);
            resultList = pick_sentences(resultList, max_length);
            return(TextUtility.join("。", resultList));
        }