Comparing version 1.0.3 to 1.0.4
26
index.js
@@ -112,7 +112,13 @@ var Tree = require("./lib/BTree"); | ||
segmentDoc: function(doc, SLPs) { | ||
segmentDoc: function(doc, asArray) { | ||
var SLPs = this.SLPs; | ||
SLPs.sort(function(item1, item2) { | ||
return item2.sistring.length - item1.sistring.length; | ||
}) | ||
var result = ""; | ||
var result; | ||
if(asArray) { | ||
result = []; | ||
} else { | ||
result = ""; | ||
} | ||
var paper = []; | ||
@@ -150,6 +156,14 @@ for(var i = 0; i < doc.length; i++) { | ||
if(paper[i].marked) { | ||
result += " " + paper[i].keyword; | ||
if(asArray && paper[i]) { | ||
result.push(paper[i].keyword); | ||
} else { | ||
result += " " + paper[i].keyword; | ||
} | ||
i += paper[i].keyword.length - 1; | ||
} else { | ||
result += " " + paper[i].char; | ||
} else if(!/\s/.test(paper[i].char)){ | ||
if(asArray) { | ||
result.push(paper[i].char); | ||
} else { | ||
result += " " + paper[i].char; | ||
} | ||
} | ||
@@ -243,2 +257,3 @@ } | ||
} | ||
this.SLPs = result; | ||
return result; | ||
@@ -565,1 +580,2 @@ }, | ||
{ | ||
"name": "pat-tree", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "PAT tree construction for Chinese documents, keyword extraction and text segmentation", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -68,5 +68,13 @@ pat-tree | ||
```javascript | ||
var result = tree.segmentDoc(doc, SLPs); | ||
var PATtree = require("pat-tree"); | ||
var tree = new PATtree(); | ||
//... | ||
tree.extractSLP(10, 0.5); | ||
var result = tree.segmentDoc(doc, asArray); | ||
``` | ||
you shold do `extractSLP` before doing text segmentation with `segmentDoc`. | ||
`doc` is the document to be segmented, data type: string. | ||
@@ -76,4 +84,6 @@ | ||
`result` is the result of document segmentation, data type: string. | ||
`result` is the result of document segmentation as an string of terms seperated by whitespaces, | ||
or an array of terms if `asArray` is set to true. | ||
### Convert to JSON | ||
@@ -278,3 +288,3 @@ | ||
* 1.0.4 `segmentDoc` no need to pass in SLPs, and enable to return array of terms. | ||
* 1.0.3 Minor change in module Node.js | ||
@@ -281,0 +291,0 @@ * 1.0.2 Gaurantee SLP sorting order when `segmentDoc()` |
37278
973
308