Parsing moved to downloading. Matching is being tweaked.
This commit is contained in:
parent
793db0f449
commit
b72f5549a5
10 changed files with 456 additions and 276 deletions
|
|
@ -1,7 +1,7 @@
|
|||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const util = require('util')
|
||||
const parser = require('./parsing')
|
||||
const loader = require('./loading')
|
||||
const matcher = require('./matching')
|
||||
const nameUtils = require('./name-utils')
|
||||
const options = require('../options')
|
||||
|
|
@ -9,7 +9,7 @@ const _ = require('lodash/fp')
|
|||
|
||||
const debug_log = require('../pp')(__filename) // KOSTIS TODO: remove
|
||||
|
||||
const OFAC_DATA_DIR = options.ofacDataDir
|
||||
const OFAC_SOURCES_DIR = path.join(options.ofacDataDir, 'sources')
|
||||
|
||||
let structs = null
|
||||
|
||||
|
|
@ -18,15 +18,15 @@ const readdir = util.promisify(fs.readdir)
|
|||
function load () {
|
||||
// NOTE: Not sure how you push code updates to existing clients. This problem
|
||||
// might pop up if new code is pushed, without re-doing setup.
|
||||
if (!OFAC_DATA_DIR) {
|
||||
if (!OFAC_SOURCES_DIR) {
|
||||
const message = 'The ofacDataDir option has not been set in lamassu.json'
|
||||
return Promise.reject(new Error(message))
|
||||
}
|
||||
|
||||
return readdir(OFAC_DATA_DIR)
|
||||
return readdir(OFAC_SOURCES_DIR)
|
||||
.then(_.flow(
|
||||
_.map(file => path.join(OFAC_DATA_DIR, file)),
|
||||
parser.parse
|
||||
_.map(file => path.join(OFAC_SOURCES_DIR, file)),
|
||||
loader.load
|
||||
))
|
||||
.then(result => {
|
||||
return (structs = result)
|
||||
|
|
@ -42,7 +42,8 @@ function makeCompatible (nameParts) {
|
|||
return _.map(_.zipObject(['partName', 'value']), props)
|
||||
}
|
||||
|
||||
function match (nameParts, birthDateString, threshold) {
|
||||
function match (nameParts, birthDateString, options) {
|
||||
const {debug} = options
|
||||
if (!structs) {
|
||||
const message = 'The OFAC data sources have not been loaded yet.'
|
||||
return Promise.reject(new Error(message))
|
||||
|
|
@ -68,10 +69,10 @@ function match (nameParts, birthDateString, threshold) {
|
|||
])(birthDateString)
|
||||
|
||||
const candidate = {parts, fullName, words, birthDate}
|
||||
// debug_log(candidate)
|
||||
debug && debug_log(candidate)
|
||||
|
||||
const result = matcher.match(structs, candidate, threshold)
|
||||
// debug_log(result)
|
||||
const result = matcher.match(structs, candidate, options)
|
||||
debug && debug_log(result)
|
||||
return result
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue