-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.js
executable file
·57 lines (53 loc) · 1.43 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*jslint node: true */
/*global module, require*/
'use strict';
var parse = require('./lib/parse');
var rules = require('./lib/rules-engine');
/** @exports nl3 **/
var nl3 = {
//@function
/**
* @name parse
* @description Returns a triple based on language used.
* @access public
* @returns {Object}
* @example nl3.parse('users who follow user 42') // returns...
* // {
* // subject: {
* // type: 'user',
* // value: undefined
* // },
* // predicate: {
* // value: 'follow'
* // },
* // object: {
* // type: 'user',
* // value: '42'
* // }
* // }
*/
parse: parse
};
/**
* @param {Object} options The options required for parsing triples
* @param {Object} options.grammar A set of valid triple relations.
* @param {Object} options.vocabulary Extend the known vocabulary by mapping a word stem to a predicate.
* @return {Object} An instance of the nl3 client.
*/
module.exports = function create(options) {
//@info triple rules
var tream = rules({
//@info defined triples
grammar: options.grammar || [],
//@info an additional set of words that map to our items with our original grammar
vocabulary: options.vocabulary || {}
});
//@info create & return the new instance
var instance = Object.create(nl3, {
rules: {
enumerable: true,
value: tream
}
});
return instance;
};