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.
|
||||
|
||||
**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
|
||||
|
||||
@ -33,13 +33,13 @@ const CEModels = require('cenode/models'); // if requred
|
||||
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
|
||||
|
||||
Clone the repository
|
||||
```
|
||||
git clone git@github.com:willwebberley/CENode.git
|
||||
git clone git@github.com:flyingsparx/CENode.git
|
||||
```
|
||||
|
||||
Install the necessary dev dependencies.
|
||||
@ -54,7 +54,7 @@ npm test
|
||||
|
||||
## 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
|
||||
|
@ -18,7 +18,7 @@ module.exports = [
|
||||
"conceptualise a ~ policy ~ P that is an entity and has the value V as ~ enabled ~ and has the agent A as ~ target ~",
|
||||
"conceptualise a ~ tell policy ~ P that is a policy",
|
||||
"conceptualise an ~ ask policy ~ P that is a policy",
|
||||
"conceptualise a ~ gist policy ~ P that is a policy",
|
||||
"conceptualise a ~ gist policy ~ P that is a policy",
|
||||
"conceptualise a ~ listen policy ~ P that is a policy",
|
||||
"conceptualise a ~ listen onbehalfof policy ~ P that is a policy",
|
||||
"conceptualise a ~ forwardall policy ~ P that is a policy and has the timestamp T as ~ start time ~ and has the value V as ~ all agents ~",
|
||||
|
@ -1,13 +1,13 @@
|
||||
{
|
||||
"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.",
|
||||
"homepage": "http://cenode.io",
|
||||
"license": "Apache-2.0",
|
||||
"author": "Will Webberley & Alun Preece",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/willwebberley/CENode"
|
||||
"url": "https://github.com/flyingsparx/CENode"
|
||||
},
|
||||
"files": [
|
||||
"src",
|
||||
|
@ -115,16 +115,16 @@ class CardHandler {
|
||||
return this.node.addSentence(`there is a ${data.response.type} card named 'msg_{uid}' that is from the agent '${this.agent.name.replace(/'/g, "\\'")}' and is to the ${card.is_from.type.name} '${card.is_from.name.replace(/'/g, "\\'")}' and has the timestamp '{now}' as timestamp and has '${data.response.message.replace(/'/g, "\\'")}' as content and is in reply to the card '${card.name}'.`);
|
||||
},
|
||||
|
||||
'gist card': (card) => {
|
||||
// Add sentence to any active gist policy queues
|
||||
for (const policy of this.node.getInstances('gist policy')) {
|
||||
if (policy.enabled === 'true' && policy.target && policy.target.name) {
|
||||
const targetName = policy.target.name;
|
||||
if (!(targetName in this.agent.policyHandler.unsentGistCards)) { this.agent.policyHandler.unsentGistCards[targetName] = []; }
|
||||
this.agent.policyHandler.unsentGistCards[targetName].push(card);
|
||||
}
|
||||
}
|
||||
},
|
||||
'gist card': (card) => {
|
||||
// Add sentence to any active gist policy queues
|
||||
for (const policy of this.node.getInstances('gist policy')) {
|
||||
if (policy.enabled === 'true' && policy.target && policy.target.name) {
|
||||
const targetName = policy.target.name;
|
||||
if (!(targetName in this.agent.policyHandler.unsentGistCards)) { this.agent.policyHandler.unsentGistCards[targetName] = []; }
|
||||
this.agent.policyHandler.unsentGistCards[targetName].push(card);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ class PolicyHandler {
|
||||
this.node = agent.node;
|
||||
this.unsentTellCards = {};
|
||||
this.unsentAskCards = {};
|
||||
this.unsentGistCards = {};
|
||||
this.unsentGistCards = {};
|
||||
this.lastSuccessfulRequest = 0;
|
||||
this.handlers = {
|
||||
|
||||
@ -105,8 +105,7 @@ 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`;
|
||||
}
|
||||
@ -160,7 +159,7 @@ class PolicyHandler {
|
||||
}
|
||||
},
|
||||
|
||||
'gist policy': (policy) => {
|
||||
'gist policy': (policy) => {
|
||||
// For each gist policy in place, send all currently-untold cards to each target
|
||||
// multiple cards to be sent to one target line-separated
|
||||
if (policy.target && policy.target.name && policy.target.address) {
|
||||
@ -175,8 +174,7 @@ 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,7 +282,6 @@ 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();
|
||||
@ -296,7 +295,6 @@ 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) {
|
||||
@ -318,11 +316,7 @@ class QuestionParser {
|
||||
property = subject.property(fixedPropertyName);
|
||||
}
|
||||
if (property && property.name === instance.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(`${subject.name} ${fixedPropertyName} the ${property.type.name} ${property.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