Ejemplo n.º 1
0
 records.forEach(function (r) {
   var s = normalize.normalizeAndDiacritics(name).score(normalize.normalizeAndDiacritics(r.nameControlled), 0.5)
   if (s > bestScore) {
     bestScore = s
     useName = r
   }
 })
Ejemplo n.º 2
0
exports.filterTripleObj = function (triple) {
  if (triple.subject.search('/fast/') > -1) {
    var obj = {type: 'fast'}

    if (triple.subject.search('/fast/NaN') > -1 || triple.object.search('/fast/NaN') > -1) return ''

    obj.id = parseInt(triple.subject.split('/fast/')[1])

    if (triple.predicate === 'http://schema.org/sameAs') {
      if (triple.object.search('id.loc.gov') > -1) obj.sameAsLc = triple.object
      if (triple.object.search('viaf.org') > -1) obj.sameAsViaf = triple.object
    }

    if (triple.predicate === 'http://www.w3.org/2004/02/skos/core#prefLabel' || triple.predicate === 'http://www.w3.org/2004/02/skos/core#altLabel' || triple.predicate === 'http://www.w3.org/2000/01/rdf-schema#label') {
      var o = N3Util.getLiteralValue(triple.object)

      if (o.length >= 2) {
        if (triple.predicate === 'http://www.w3.org/2004/02/skos/core#prefLabel') obj.prefLabel = o
        if (triple.predicate === 'http://www.w3.org/2004/02/skos/core#altLabel') obj.altLabel = o
        if (triple.predicate === 'http://www.w3.org/2000/01/rdf-schema#label') obj.label = o
        var normalO = utils.singularize(utils.normalizeAndDiacritics(o))
        obj.normalized = normalO
      }
    }

    return obj
  } else {
    if (triple.predicate === 'http://www.w3.org/2000/01/rdf-schema#label') {
      var sameAs = {type: 'sameAsLabel'}
      sameAs.label = N3Util.getLiteralValue(triple.object)
      sameAs.subject = triple.subject
      sameAs.normalized = utils.singularize(utils.normalizeAndDiacritics(sameAs.label))

      return sameAs
    } else {
      return ''
    }
  }
}
Ejemplo n.º 3
0
 db.returnCollectionRegistry('agents', (err, agents) => {
   if (err) console.log(err)
   agents.find({ nameNormalized: normalize.normalizeAndDiacritics(name) }).toArray((err, records) => {
     if (err) console.log(err)
     if (records.length === 0) {
       if (cb) cb(err, {name: name, data: false})
     } else {
       // figure out which to use based on the best controled term name
       var bestScore = -1
       var useName = false
       records.forEach(function (r) {
         var s = normalize.normalizeAndDiacritics(name).score(normalize.normalizeAndDiacritics(r.nameControlled), 0.5)
         if (s > bestScore) {
           bestScore = s
           useName = r
         }
       })
       if (cb) cb(err, {name: name, data: useName})
     }
   })
 })