-
Notifications
You must be signed in to change notification settings - Fork 2
Further Examples
Will Webberley edited this page Jan 22, 2017
·
3 revisions
This article demonstrates simple examples using the CENode library.
In all cases, CENode has been imported into either a webpage or into a Node app.
Note: you can enter a Node interactive prompt by running node in your terminal.
const node = new CENode();
node.addSentence('conceptualise a ~ person ~ P')
node.concepts.person.name // -> "person"const node = new CENode();
node.addSentence('conceptualise a ~ house ~ H')
node.addSentence('conceptualise a ~ person ~ P that ~ lives in ~ the house H')
node.concepts.lives_in // -> [house CEConcept]const node = new CENode();
node.addSentence('conceptualise a ~ person ~ P that has the value V as ~ age ~')
node.addSentence('there is a person named Jane that has 53 as age');
node.instances.jane.age // -> "53"const node = new CENode();
node.addSentence('conceptualise a ~ person ~ P')
node.addSentence('conceptualise the person P1 ~ is married to ~ the person P2')
node.addSentence('there is a person named Jane')
node.addSentence('the person Jane is married to the person Sam')
node.instances.jane.is_married_to // -> [Sam CEInstance]const node = new CENode();
node.addSentence('conceptualise a ~ house ~ H')
node.addSentence('conceptualise a ~ person ~ P that ~ lives in ~ the house H')
node.addSentence('conceptualise a ~ teacher ~ T that is a person')
node.addSentence('there is a teacher named \'Mrs Smith\' that lives in the house \'Number 23\'')
node.instances.mrs_smith.lives_in // -> [Number 23 CEInstance]const node = new CENode();
node.addSentence('conceptualise a ~ house ~ H')
node.addSentence('conceptualise a ~ person ~ P that ~ lives in ~ the house H')
node.addSentence('conceptualise a ~ professional ~ P that has the value V as ~ job title ~')
node.addSentence('conceptualise a ~ teacher ~ T that is a person and is a professional')
node.addSentence('there is a teacher named \'Mrs Smith\; that lives in the house \'Number 23\' and has \'English Teacher\' as job title')
node.instances.mrs_smith.lives_in // -> [Number 23 CEInstance]
node.instances.mrs_smith.job_title // -> "English Teacher"const node = new CENode();
node.addSentence('conceptualise a ~ barrista ~ B')
node.addSentence('conceptualise a ~ cool dude ~ C')
node.addSentence('conceptualise a ~ person ~ P')
node.addSentence('there is a person named Ben that is a barrista and a cool dude')
node.instances.ben.ce // -> "there is a person named Ben that is a 'barrista' and is a 'cool dude'"Note: for rules to work correctly we should instantiate CENode with the core model.
const node = new CENode(CEModels.core)
node.addSentence('conceptualise a ~ celestial body ~ C')
node.addSentence('conceptualise the celestial body C ~ orbits ~ the celestial body D and ~ is orbited by ~ the celestial body E')
node.addSentence('conceptualise a ~ planet ~ P that is a celestial body')
node.addSentence('conceptualise a ~ star ~ S that is a celestial body')
node.addSentence('there is a rule named r1 that has \'if the planet C ~ orbits ~ the star D then the star D ~ is orbited by ~ the planet C\' as instruction.')
node.addSentence('there is a planet named Earth that orbits the star Sol')
node.instances.sol.is_orbited_by.name // -> "Earth"Note: we need agents for cards to work, so instantiate CENode with the core model.
const node = new CENode(CEModels.core)
node.attachAgent()
node.agent.setName('Mycroft')
node.addSentence('there is an ask card named card1 that is to the agent Mycroft and is from the individual Will and has \'what is Mycroft?\' as content')
node.instances.card1.content // -> "what is Mycroft?"
setTimeout(() => {
for (const card of node.getInstances('card', true)) {
if (card.is_to.name === 'Will') {
card.content // -> "Mycroft is an agent."
}
}
}, 1000);