Examples for @rdfjs/score
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
import housemd from 'housemd' | |
import rdf from 'rdf-ext' | |
const ns = { | |
rdf: rdf.namespace('http://www.w3.org/1999/02/22-rdf-syntax-ns#'), | |
schema: rdf.namespace('http://schema.org/') | |
} | |
// import he House M.D. dataset | |
const dataset = rdf.dataset(housemd({ factory: rdf })) | |
// get all subject named nodes in the dataset | |
const subjects = rdf.termSet( | |
rdf.clownface({ dataset }) | |
.in() | |
.filter(ptr => ptr.term.termType === 'NamedNode') | |
.terms | |
) | |
// get all literal objects in the dataset | |
const literals = rdf.termSet( | |
rdf.clownface({ dataset }) | |
.has(ns.rdf.type, ns.schema.Person) | |
.out(ns.schema.givenName) | |
.filter(ptr => ptr.term.termType === 'Literal') | |
.terms | |
) | |
// the input structures that will be handed over to the score functions | |
const input = { dataset, terms: subjects } | |
const inputLiterals = { dataset, terms: literals } | |
export { | |
input, | |
inputLiterals, | |
ns | |
} |
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
import rdf from 'rdf-ext' | |
import { input } from './common.js' | |
function example () { | |
const results = rdf.score.sort(rdf.score.pageRank()(input)) | |
for (const result of results) { | |
console.log(`${result.term.value} (${result.score})`) | |
} | |
} | |
example() |
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
import rdf from 'rdf-ext' | |
import { input, ns } from './common.js' | |
function example () { | |
const results = rdf.score.sort( | |
rdf.score.fallback([ | |
rdf.score.exists({ subject: rdf.namedNode('https://housemd.rdf-ext.org/person/lisa-cuddy') }), | |
rdf.score.product([ | |
rdf.score.type(ns.schema.Person), | |
rdf.score.pageRank() | |
]) | |
])(input) | |
) | |
for (const result of results) { | |
console.log(`${result.term.value} (${result.score})`) | |
} | |
} | |
example() |
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
import rdf from 'rdf-ext' | |
import { inputLiterals } from './common.js' | |
function example () { | |
const results = rdf.score.sort(rdf.score.language(['en', 'de', '*'])(inputLiterals)) | |
for (const result of results) { | |
console.log(`${result.term.value} (${result.score})`) | |
} | |
} | |
example() |
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
{ | |
"name": "rdfjs-score-examples", | |
"version": "0.0.0", | |
"description": "Examples for @rdfjs/score", | |
"type": "module", | |
"main": "example1.js", | |
"author": "Thomas Bergwinkl <bergi@axolotlfarm.org> (https://www.bergnet.org/people/bergi/card#me)", | |
"license": "MIT", | |
"dependencies": { | |
"housemd": "^0.1.0", | |
"rdf-ext": "^2.1.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment