Comparing version 0.1.6 to 0.1.7
85
index.js
@@ -141,3 +141,3 @@ var Tree = require("./lib/BTree"); | ||
this._insert(tree, tree.root, sistring, index); | ||
this._updateParents(); | ||
//this._updateParents(); | ||
}, | ||
@@ -278,2 +278,4 @@ | ||
this._updateParents(subtreeRoot); | ||
/* | ||
@@ -286,45 +288,44 @@ if(!this._checkConnections()) { | ||
_updateParents: function() { | ||
_updateParents: function(node) { | ||
var owner = this; | ||
this.postOrderTraverse(function(node) { | ||
if(node.data.type == owner.INTERNAL) { | ||
var sistrings = []; | ||
var left = node.left; | ||
var right = node.right; | ||
var externalNodeNum = 0; | ||
var totalFrequency = 0; | ||
if(left && right) { | ||
if(left.data.type == owner.INTERNAL) { | ||
externalNodeNum += left.data.externalNodeNum; | ||
totalFrequency += left.data.totalFrequency; | ||
sistrings = sistrings.concat(left.data.sistrings); | ||
} else if(left.data.type == owner.EXTERNAL) { | ||
externalNodeNum += 1; | ||
totalFrequency += left.data.indexes.length; | ||
sistrings.push(left); | ||
} else { | ||
console.trace(); | ||
throw "unknown node type (neither internal nor external)" | ||
} | ||
if(right.data.type == owner.INTERNAL) { | ||
externalNodeNum += right.data.externalNodeNum; | ||
totalFrequency += right.data.totalFrequency; | ||
sistrings = sistrings.concat(right.data.sistrings); | ||
} else if(right.data.type == owner.EXTERNAL) { | ||
externalNodeNum += 1; | ||
totalFrequency += right.data.indexes.length; | ||
sistrings.push(right); | ||
} else { | ||
console.trace(); | ||
throw "unknown node type (neither internal nor external)" | ||
} | ||
} else { | ||
console.trace(); | ||
throw "internal node lost left or right child" | ||
} | ||
node.data.sistrings = sistrings; | ||
node.data.externalNodeNum = externalNodeNum; | ||
node.data.totalFrequency = totalFrequency; | ||
var sistrings = []; | ||
var left = node.left; | ||
var right = node.right; | ||
var externalNodeNum = 0; | ||
var totalFrequency = 0; | ||
if(left && right) { | ||
if(left.data.type == owner.INTERNAL) { | ||
externalNodeNum += left.data.externalNodeNum; | ||
totalFrequency += left.data.totalFrequency; | ||
sistrings = sistrings.concat(left.data.sistrings); | ||
} else if(left.data.type == owner.EXTERNAL) { | ||
externalNodeNum += 1; | ||
totalFrequency += left.data.indexes.length; | ||
sistrings.push(left); | ||
} else { | ||
console.trace(); | ||
throw "unknown node type (neither internal nor external)" | ||
} | ||
}); | ||
if(right.data.type == owner.INTERNAL) { | ||
externalNodeNum += right.data.externalNodeNum; | ||
totalFrequency += right.data.totalFrequency; | ||
sistrings = sistrings.concat(right.data.sistrings); | ||
} else if(right.data.type == owner.EXTERNAL) { | ||
externalNodeNum += 1; | ||
totalFrequency += right.data.indexes.length; | ||
sistrings.push(right); | ||
} else { | ||
console.trace(); | ||
throw "unknown node type (neither internal nor external)" | ||
} | ||
} else { | ||
console.trace(); | ||
throw "internal node lost left or right child" | ||
} | ||
node.data.sistrings = sistrings; | ||
node.data.externalNodeNum = externalNodeNum; | ||
node.data.totalFrequency = totalFrequency; | ||
if(node.parent) { | ||
this._updateParents(node.parent); | ||
} | ||
}, | ||
@@ -331,0 +332,0 @@ |
{ | ||
"name": "pat-tree", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"description": "PAT tree construction for Chinese documents", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -6,5 +6,7 @@ pat-tree | ||
WARNING: This project is now in development and used for academic purpose, | ||
DO NOT use this module until the WARNING statement is removed. | ||
# WARNING | ||
This project is now in development and used for academic purpose, | ||
**DO NOT** use this module until the **WARNING** statement is removed. | ||
# Installation | ||
@@ -14,6 +16,2 @@ | ||
# Test | ||
npm test | ||
# Usage | ||
@@ -119,2 +117,3 @@ | ||
* 0.1.7 Improve performance | ||
* 0.1.6 Improve performance | ||
@@ -121,0 +120,0 @@ * 0.1.5 Add functionality of SLP extraction |
27380
123