-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add middle initial and new venue classification (#117)
- Loading branch information
Showing
8 changed files
with
137 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const Classification = require('../classification/Classification') | ||
|
||
class MiddleInitialClassification extends Classification { | ||
constructor (confidence, meta) { | ||
super(confidence, meta) | ||
this.label = 'middle_initial' | ||
} | ||
} | ||
|
||
module.exports = MiddleInitialClassification |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const Classification = require('./MiddleInitialClassification') | ||
|
||
module.exports.tests = {} | ||
|
||
module.exports.tests.constructor = (test) => { | ||
test('constructor', (t) => { | ||
let c = new Classification() | ||
t.false(c.public) | ||
t.equals(c.label, 'middle_initial') | ||
t.equals(c.confidence, 1.0) | ||
t.deepEqual(c.meta, {}) | ||
t.end() | ||
}) | ||
} | ||
|
||
module.exports.all = (tape, common) => { | ||
function test (name, testFunction) { | ||
return tape(`MiddleInitialClassification: ${name}`, testFunction) | ||
} | ||
|
||
for (var testCase in module.exports.tests) { | ||
module.exports.tests[testCase](test, common) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const PhraseClassifier = require('./super/PhraseClassifier') | ||
const MiddleInitialClassification = require('../classification/MiddleInitialClassification') | ||
|
||
const SingleLetterRegExp = /^[A-Za-z]\.?$/ | ||
|
||
class MiddleInitialClassifier extends PhraseClassifier { | ||
setup () { | ||
} | ||
|
||
each (span) { | ||
if (SingleLetterRegExp.test(span.body)) { | ||
span.classify(new MiddleInitialClassification(1)) | ||
} | ||
} | ||
} | ||
|
||
module.exports = MiddleInitialClassifier |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
const MiddleInitialClassifier = require('./MiddleInitialClassifier') | ||
const MiddleInitialClassification = require('../classification/MiddleInitialClassification') | ||
const Span = require('../tokenization/Span') | ||
const classifier = new MiddleInitialClassifier() | ||
|
||
module.exports.tests = {} | ||
|
||
function classify (body) { | ||
let s = new Span(body) | ||
classifier.each(s, null, 1) | ||
return s | ||
} | ||
|
||
module.exports.tests.classify = (test) => { | ||
const valid = [ | ||
'M.', | ||
'M' | ||
] | ||
|
||
valid.forEach(token => { | ||
test(`classify: ${token}`, (t) => { | ||
let s = classify(token) | ||
t.deepEqual(s.classifications, { | ||
MiddleInitialClassification: new MiddleInitialClassification(1.0) | ||
}) | ||
t.end() | ||
}) | ||
}) | ||
|
||
const invalid = [ | ||
'Mae', | ||
'122', | ||
'M,', | ||
'&', | ||
'Mr', | ||
'Esq' | ||
] | ||
|
||
invalid.forEach(token => { | ||
test(`classify: ${token}`, (t) => { | ||
let s = classify(token) | ||
t.deepEqual(s.classifications, {}) | ||
t.end() | ||
}) | ||
}) | ||
} | ||
|
||
module.exports.all = (tape, common) => { | ||
function test (name, testFunction) { | ||
return tape(`MiddleInitialClassifier: ${name}`, testFunction) | ||
} | ||
|
||
for (var testCase in module.exports.tests) { | ||
module.exports.tests[testCase](test, common) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters