Support for SentenceNode?
beaugunderson opened this issue · 5 comments
It appears that this module supports WordNode but not SentenceNode. In diagnosing this I also figured out that I could just use sentenceNode.toString(). :)
Could you give me a code example? I'm thinking your confused between NLCST and TextOM, if so, I'll make sure I'll write that up better!
It's very possible that I'm confused. :)
Here's how I tried to use it before I realized sentence nodes had a .toString() method:
'use strict';
var nlcstToString = require('nlcst-to-string');
var ParseEnglish = require('parse-english');
var Retext = require('retext');
var retextVisit = require('retext-visit');
var retext = new Retext(new ParseEnglish())
.use(retextVisit);
var text = 'This is a sentence. This is another sentence.';
retext.parse(text, function (err, tree) {
if (err) {
throw err;
}
var sentences = [];
tree.visitType(tree.SENTENCE_NODE, function (sentenceNode) {
sentences.push(nlcstToString(sentenceNode));
});
sentences.forEach(function (sentence, i) {
console.log(i, sentence);
});
});Here's the error I got:
◼ reginald/root ~/p/sentence-parser-comparisons node test.js
/root/p/sentence-parser-comparisons/node_modules/nlcst-to-string/index.js:20
length = children.length;
^
TypeError: Cannot read property 'length' of undefined
at nlcstToString (/root/p/sentence-parser-comparisons/node_modules/nlcst-to-string/index.js:20:22)
at /root/p/sentence-parser-comparisons/test.js:21:20
at wrapper (/root/p/sentence-parser-comparisons/node_modules/retext-visit/index.js:69:20)
at ParagraphNode.visit (/root/p/sentence-parser-comparisons/node_modules/retext-visit/index.js:31:13)
at RootNode.visit (/root/p/sentence-parser-comparisons/node_modules/retext-visit/index.js:41:31)
at RootNode.visitType (/root/p/sentence-parser-comparisons/node_modules/retext-visit/index.js:73:10)
at /root/p/sentence-parser-comparisons/test.js:20:8
at next (/root/p/sentence-parser-comparisons/node_modules/retext/node_modules/ware/lib/index.js:72:27)
at Ware.<anonymous> (/root/p/sentence-parser-comparisons/node_modules/retext/node_modules/ware/node_modules/wrap-fn/index.js:74:42)
at Ware.<anonymous> (/root/p/sentence-parser-comparisons/node_modules/retext/node_modules/ware/node_modules/wrap-fn/index.js:48:27)Right! I should've explained better.
The thing is, with retext, your interacting with TextOM instead of NLCST. TextOM provides an object-oriented approach, meaning every node/object has methods such as 'toString' and 'valueOf', and such. Whereas, with NLCST (used internally by parse-latin and such), every node/object is just a vanilla object without fancy methods. That's why this library is needed, but it's not useful if retext is also used!
Did that help?
Definitely helped, thanks for the explanation!
Okay, great! I’ll add a note in the Readme though, somewhere tomorrow.