Compare commits
7 Commits
gist-polic
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
a82756ab73 | ||
|
2c527f95fd | ||
|
6229aa5aaa | ||
|
505dec2ac4 | ||
|
feb2962d36 | ||
|
7080db074a | ||
|
65da1e698d |
@ -4,7 +4,7 @@ A pure JavaScript implementation of the ITA project's CEStore - called CENode. C
|
||||
|
||||
Please visit the project's [home page](http://cenode.io) for more information and for documentation.
|
||||
|
||||
**We recommend beginners check out the [Getting Started Guide](https://github.com/flyingsparx/CENode/wiki/Getting-Started-Guide) before continuing.**
|
||||
**We recommend beginners check out the [Getting Started Guide](https://github.com/willwebberley/CENode/wiki/Getting-Started-Guide) before continuing.**
|
||||
|
||||
## Getting started
|
||||
|
||||
@ -33,13 +33,13 @@ const CEModels = require('cenode/models'); // if requred
|
||||
const node = new CENode(CEModels.core);
|
||||
```
|
||||
|
||||
See the [Wiki](https://github.com/flyingsparx/CENode/wiki) for further guides and the API reference.
|
||||
See the [Wiki](https://github.com/willwebberley/CENode/wiki) for further guides and the API reference.
|
||||
|
||||
## Testing
|
||||
|
||||
Clone the repository
|
||||
```
|
||||
git clone git@github.com:flyingsparx/CENode.git
|
||||
git clone git@github.com:willwebberley/CENode.git
|
||||
```
|
||||
|
||||
Install the necessary dev dependencies.
|
||||
@ -54,7 +54,7 @@ npm test
|
||||
|
||||
## More Information
|
||||
|
||||
See the CENode [Wiki](https://github.com/flyingsparx/CENode/wiki) for more information, guides, and the API reference.
|
||||
See the CENode [Wiki](https://github.com/willwebberley/CENode/wiki) for more information, guides, and the API reference.
|
||||
|
||||
|
||||
## Licence
|
||||
|
@ -1,13 +1,13 @@
|
||||
{
|
||||
"name": "cenode",
|
||||
"version": "3.0.11",
|
||||
"version": "3.0.12",
|
||||
"description": "A pure JavaScript implementation of the ITA project's CEStore - called CENode. CENode is able to understand the basic sentence types parsed by the CEStore, such as conceptualising and instance creation and modification.",
|
||||
"homepage": "http://cenode.io",
|
||||
"license": "Apache-2.0",
|
||||
"author": "Will Webberley & Alun Preece",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/flyingsparx/CENode"
|
||||
"url": "https://github.com/willwebberley/CENode"
|
||||
},
|
||||
"files": [
|
||||
"src",
|
||||
|
@ -105,7 +105,8 @@ class PolicyHandler {
|
||||
for (const to of card.is_tos) {
|
||||
if (to.id === policy.target.id) { inCard = true; break; }
|
||||
}
|
||||
if (!inCard) { card.addRelationship('is to', policy.target);
|
||||
if (!inCard) {
|
||||
card.addRelationship('is to', policy.target);
|
||||
}
|
||||
data += `${card.ce}\n`;
|
||||
}
|
||||
@ -174,7 +175,8 @@ class PolicyHandler {
|
||||
for (const to of card.is_tos) {
|
||||
if (to.id === policy.target.id) { inCard = true; break; }
|
||||
}
|
||||
if (!inCard) { card.addRelationship('is to', policy.target);
|
||||
if (!inCard) {
|
||||
card.addRelationship('is to', policy.target);
|
||||
}
|
||||
data += `${card.ce}\n`;
|
||||
}
|
||||
|
@ -282,6 +282,7 @@ class QuestionParser {
|
||||
const data = t.match(/^(\bwho\b|\bwhat\b) ([a-zA-Z0-9_ ]*)/i);
|
||||
const body = data[2].replace(/\ban\b/gi, '').replace(/\bthe\b/gi, '').replace(/\ba\b/gi, '');
|
||||
const tokens = body.split(' ');
|
||||
const uniqueResponses = new Set([]);
|
||||
let instance;
|
||||
for (let i = 0; i < tokens.length; i += 1) {
|
||||
const testString = tokens.slice(tokens.length - (i + 1), tokens.length).join(' ').trim();
|
||||
@ -295,6 +296,7 @@ class QuestionParser {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (instance) {
|
||||
const propertyName = tokens.splice(0, tokens.length - instance.name.split(' ').length).join(' ').trim();
|
||||
for (let i = 0; i < this.node.instances.length; i += 1) {
|
||||
@ -316,7 +318,11 @@ class QuestionParser {
|
||||
property = subject.property(fixedPropertyName);
|
||||
}
|
||||
if (property && property.name === instance.name) {
|
||||
return QuestionParser.success(`${subject.name} ${fixedPropertyName} the ${property.type.name} ${property.name}.`);
|
||||
uniqueResponses.add(`${subject.name} ${fixedPropertyName} the ${property.type.name} ${property.name}.`);
|
||||
}
|
||||
const responsesArray = Array.from(uniqueResponses);
|
||||
if (responsesArray.length > 0 && i === this.node.instances.length - 1) {
|
||||
return QuestionParser.success(responsesArray.join(' '));
|
||||
}
|
||||
}
|
||||
return QuestionParser.success(`Sorry - I don't know that property about the ${instance.type.name} ${instance.name}.`);
|
||||
|
40
test/QuestionParser.js
Normal file
40
test/QuestionParser.js
Normal file
@ -0,0 +1,40 @@
|
||||
const CENode = require('../src/CENode.js');
|
||||
const CEModels = require('../models/index.js');
|
||||
const expect = require('expect.js');
|
||||
const myName = 'User'
|
||||
const PLANETS_MODEL = [
|
||||
"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.",
|
||||
"there is a rule named 'r2' that has 'if the planet C ~ is orbited by ~ the moon D then the moon D ~ orbits ~ the planet C' as instruction.",
|
||||
"conceptualise a ~ celestial body ~ C.",
|
||||
"conceptualise the celestial body C ~ orbits ~ the celestial body D and ~ is orbited by ~ the celestial body E.",
|
||||
"conceptualise a ~ planet ~ P that is a celestial body and is an imageable thing.",
|
||||
"conceptualise a ~ star ~ S that is a celestial body.",
|
||||
"there is a star named sun.",
|
||||
"there is a planet named Venus that orbits the star 'sun' and has 'media/Venus.jpg' as image.",
|
||||
"there is a planet named Mercury that orbits the star 'sun' and has 'media/Mercury.jpg' as image."
|
||||
]
|
||||
|
||||
let node;
|
||||
describe('CEQuestionParser', function() {
|
||||
describe('What relation questions', function () {
|
||||
this.timeout(2050);
|
||||
before(function() {
|
||||
node = new CENode(CEModels.core, PLANETS_MODEL);
|
||||
node.attachAgent();
|
||||
node.agent.setName('agent1');
|
||||
});
|
||||
it('returns the correct number of responses', (done) => {
|
||||
const message = 'what orbits the sun?';
|
||||
const askCard = "there is a nl card named '{uid}' that is to the agent 'agent1' and is from the individual '" + myName + "' and has the timestamp '{now}' as timestamp and has '" + message.replace(/'/g, "\\'")+"' as content.";
|
||||
|
||||
node.addSentence(askCard);
|
||||
|
||||
setTimeout(function() {
|
||||
const cards = node.concepts.card.allInstances;
|
||||
const card = cards[cards.length - 1];
|
||||
expect(card.content).to.equal('Venus orbits the star sun. Mercury orbits the star sun.');
|
||||
done();
|
||||
}, 2000);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user