Compare commits
2 Commits
master
...
gist-polic
Author | SHA1 | Date | |
---|---|---|---|
|
91823ec63b | ||
|
ee4450deb4 |
@ -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.
|
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/willwebberley/CENode/wiki/Getting-Started-Guide) before continuing.**
|
**We recommend beginners check out the [Getting Started Guide](https://github.com/flyingsparx/CENode/wiki/Getting-Started-Guide) before continuing.**
|
||||||
|
|
||||||
## Getting started
|
## Getting started
|
||||||
|
|
||||||
@ -33,13 +33,13 @@ const CEModels = require('cenode/models'); // if requred
|
|||||||
const node = new CENode(CEModels.core);
|
const node = new CENode(CEModels.core);
|
||||||
```
|
```
|
||||||
|
|
||||||
See the [Wiki](https://github.com/willwebberley/CENode/wiki) for further guides and the API reference.
|
See the [Wiki](https://github.com/flyingsparx/CENode/wiki) for further guides and the API reference.
|
||||||
|
|
||||||
## Testing
|
## Testing
|
||||||
|
|
||||||
Clone the repository
|
Clone the repository
|
||||||
```
|
```
|
||||||
git clone git@github.com:willwebberley/CENode.git
|
git clone git@github.com:flyingsparx/CENode.git
|
||||||
```
|
```
|
||||||
|
|
||||||
Install the necessary dev dependencies.
|
Install the necessary dev dependencies.
|
||||||
@ -54,7 +54,7 @@ npm test
|
|||||||
|
|
||||||
## More Information
|
## More Information
|
||||||
|
|
||||||
See the CENode [Wiki](https://github.com/willwebberley/CENode/wiki) for more information, guides, and the API reference.
|
See the CENode [Wiki](https://github.com/flyingsparx/CENode/wiki) for more information, guides, and the API reference.
|
||||||
|
|
||||||
|
|
||||||
## Licence
|
## Licence
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "cenode",
|
"name": "cenode",
|
||||||
"version": "3.0.12",
|
"version": "3.0.11",
|
||||||
"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.",
|
"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",
|
"homepage": "http://cenode.io",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"author": "Will Webberley & Alun Preece",
|
"author": "Will Webberley & Alun Preece",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/willwebberley/CENode"
|
"url": "https://github.com/flyingsparx/CENode"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"src",
|
"src",
|
||||||
|
@ -105,8 +105,7 @@ class PolicyHandler {
|
|||||||
for (const to of card.is_tos) {
|
for (const to of card.is_tos) {
|
||||||
if (to.id === policy.target.id) { inCard = true; break; }
|
if (to.id === policy.target.id) { inCard = true; break; }
|
||||||
}
|
}
|
||||||
if (!inCard) {
|
if (!inCard) { card.addRelationship('is to', policy.target);
|
||||||
card.addRelationship('is to', policy.target);
|
|
||||||
}
|
}
|
||||||
data += `${card.ce}\n`;
|
data += `${card.ce}\n`;
|
||||||
}
|
}
|
||||||
@ -175,8 +174,7 @@ class PolicyHandler {
|
|||||||
for (const to of card.is_tos) {
|
for (const to of card.is_tos) {
|
||||||
if (to.id === policy.target.id) { inCard = true; break; }
|
if (to.id === policy.target.id) { inCard = true; break; }
|
||||||
}
|
}
|
||||||
if (!inCard) {
|
if (!inCard) { card.addRelationship('is to', policy.target);
|
||||||
card.addRelationship('is to', policy.target);
|
|
||||||
}
|
}
|
||||||
data += `${card.ce}\n`;
|
data += `${card.ce}\n`;
|
||||||
}
|
}
|
||||||
|
@ -282,7 +282,6 @@ class QuestionParser {
|
|||||||
const data = t.match(/^(\bwho\b|\bwhat\b) ([a-zA-Z0-9_ ]*)/i);
|
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 body = data[2].replace(/\ban\b/gi, '').replace(/\bthe\b/gi, '').replace(/\ba\b/gi, '');
|
||||||
const tokens = body.split(' ');
|
const tokens = body.split(' ');
|
||||||
const uniqueResponses = new Set([]);
|
|
||||||
let instance;
|
let instance;
|
||||||
for (let i = 0; i < tokens.length; i += 1) {
|
for (let i = 0; i < tokens.length; i += 1) {
|
||||||
const testString = tokens.slice(tokens.length - (i + 1), tokens.length).join(' ').trim();
|
const testString = tokens.slice(tokens.length - (i + 1), tokens.length).join(' ').trim();
|
||||||
@ -296,7 +295,6 @@ class QuestionParser {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (instance) {
|
if (instance) {
|
||||||
const propertyName = tokens.splice(0, tokens.length - instance.name.split(' ').length).join(' ').trim();
|
const propertyName = tokens.splice(0, tokens.length - instance.name.split(' ').length).join(' ').trim();
|
||||||
for (let i = 0; i < this.node.instances.length; i += 1) {
|
for (let i = 0; i < this.node.instances.length; i += 1) {
|
||||||
@ -318,11 +316,7 @@ class QuestionParser {
|
|||||||
property = subject.property(fixedPropertyName);
|
property = subject.property(fixedPropertyName);
|
||||||
}
|
}
|
||||||
if (property && property.name === instance.name) {
|
if (property && property.name === instance.name) {
|
||||||
uniqueResponses.add(`${subject.name} ${fixedPropertyName} the ${property.type.name} ${property.name}.`);
|
return QuestionParser.success(`${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}.`);
|
return QuestionParser.success(`Sorry - I don't know that property about the ${instance.type.name} ${instance.name}.`);
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
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