adelevie / walverine

Extract case law citations with Node
Other
55 stars 9 forks source link

Clash with unitedstates/citation namespace #6

Open adelevie opened 10 years ago

adelevie commented 10 years ago
var fs = require('fs');
var walverine = require('walverine');
var _ = require('underscore');
require('citation');
var text = fs.readFileSync('sample1.txt','utf8');
var citations = Citation.find(text);
_.each(citations, function(citation) {
  console.log(citation);
});
var courtCases = walverine.get_citations(text);
console.log(courtCases.length);
_.each(courtCases, function(courtCase) {
  console.log(courtCase);
});

Output:

/Users/adelevie/programming/citations.io/node_modules/walverine/walverine.js:653
    var citation = new Citation(volume, reporter, page);
                   ^
TypeError: object is not a function
    at Object.Walverine.extract_base_citation (/Users/adelevie/programming/citations.io/node_modules/walverine/walverine.js:653:20)
    at Object.Walverine.get_citations (/Users/adelevie/programming/citations.io/node_modules/walverine/walverine.js:1101:29)
    at Object.<anonymous> (/Users/adelevie/programming/citations.io/parse.js:15:28)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:901:3

A simple fix would be to find/replace Citation in Walverine, and call it something like WalverineCitation.

Any objections?

konklone commented 10 years ago

This is Citation's fault - it shouldn't leak a namespace at all. You should be forced to say...

var Citation = require('citation')

...to "capture" the citation module in the name of your choice. I'm fixing this now in Citation, and I think Walverine should work the same way.

I'm not sure why this is, but right now, when I do a require('walverine'), I get this in the node REPL:

> Walverine
ReferenceError: Walverine is not defined
    at repl:1:2
    at REPLServer.self.eval (repl.js:110:21)
    at Interface.<anonymous> (repl.js:239:12)
    at Interface.EventEmitter.emit (events.js:95:17)
    at Interface._onLine (readline.js:202:10)
    at Interface._line (readline.js:531:8)
    at Interface._ttyWrite (readline.js:760:14)
    at ReadStream.onkeypress (readline.js:99:10)
    at ReadStream.EventEmitter.emit (events.js:98:17)
    at emitKey (readline.js:1095:12)
> WalverineCitation
[Function]
konklone commented 10 years ago

Fixed it in Citation at https://github.com/unitedstates/citation/commit/ab19821e8661668b7365b2353886252d71fef984