You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 24, 2025. It is now read-only.
Node.js interface to the CallByMeaning network server. For further information, consult the website of the server-side project: [CallByMeaning](https://github.com/cbmjs/CallByMeaning).
3
+
Node.js interface to the cbmjs network server. For further information, consult the website of the server-side project: [cbm-engine](https://github.com/cbmjs/cbm-engine).
4
4
5
5
## Introduction
6
6
@@ -18,7 +18,7 @@ The module exports a single constructor which can be used to open an API connect
18
18
constcbm=newCallByMeaning();
19
19
```
20
20
21
-
In case that you are running your own copy of the CallByMeaning server, the constructor takes the hostname of the server as an optional argument. The default option evaluates to "[https://call-by-meaning.herokuapp.com](https://call-by-meaning.herokuapp.com/)".
21
+
In case that you are running your own copy of the cbmjs server, the constructor takes the hostname of the server as an optional argument. The default option evaluates to "[https://call-by-meaning.herokuapp.com](https://call-by-meaning.herokuapp.com/)".
We can then use the following six methods to query the CallByMeaning API:
33
+
We can then use the following six methods to query the cbmjs API:
34
34
35
35
## Methods
36
36
37
37
### `.lookup(uri[, type])`
38
38
39
-
This method expects a valid CallByMeaning URI as its first argument.
39
+
This method expects a valid cbmjs URI as its first argument.
40
40
`type` is an (optional) string that specifies the type of the GET request. It can have the keys `c`, `f` or `r`. This method is asynchronous and returns a promise that, when fulfilled, returns an object with two properties.`statusCode` which contains the status code of the request and `body` that holds the result set from the query.
This method finds out what the CallByMeaning URI is for a given text, applying steps such as reducing English words to their root form and removing special characters.
53
+
This method finds out what the cbmjs URI is for a given text, applying steps such as reducing English words to their root form and removing special characters.
This method finds all the functions that correspond to given concepts and returns an array containing them. It can be called with two different ways. Either by providing only an object containing the search parameters or by providing the parameters themselves as arguments. This method is asynchronous and returns a promise that, when fulfilled, returns an object with two properties.`statusCode` which contains the status code of the request and `body` that holds the result set from the query. For a full overview of search parameters, check the [documentation](https://github.com/cbmjs/CallByMeaning/blob/master/docs/GETBYMEANING.md).
63
+
This method finds all the functions that correspond to given concepts and returns an array containing them. It can be called with two different ways. Either by providing only an object containing the search parameters or by providing the parameters themselves as arguments. This method is asynchronous and returns a promise that, when fulfilled, returns an object with two properties.`statusCode` which contains the status code of the request and `body` that holds the result set from the query. For a full overview of search parameters, check the [documentation](https://github.com/cbmjs/cbm-engine/blob/master/docs/GETBYMEANING.md).
if (result.statusCode===200) console.log('Success!');
75
75
// insert code here
76
76
}).catch((error) =>console.error(error));
77
77
```
78
78
79
79
### `.call(...args)`
80
80
81
-
This method takes the search parameters and after finding an appropriate function - a function with the same concepts as inputs and outputs, but (maybe) in different units, that is - executes it and returns the result. If the (optional) argument `returnCode` is set to true, it instead returns the .js file's name and the description of the function. It can be called with two different ways. Either by providing only an object containing the search parameters (and maybe the optional returnCode as a second argument) or by providing the parameters themselves as arguments. This method is asynchronous and returns a promise that, when fulfilled, returns an object with two properties.`statusCode` which contains the status code of the request and `body` that holds the result set from the query. For a full overview of search parameters, check the [documentation](https://github.com/cbmjs/CallByMeaning/blob/master/docs/CALLBYMEANING.md).
81
+
This method takes the search parameters and after finding an appropriate function - a function with the same concepts as inputs and outputs, but (maybe) in different units, that is - executes it and returns the result. If the (optional) argument `returnCode` is set to true, it instead returns the .js file's name and the description of the function. It can be called with two different ways. Either by providing only an object containing the search parameters (and maybe the optional returnCode as a second argument) or by providing the parameters themselves as arguments. This method is asynchronous and returns a promise that, when fulfilled, returns an object with two properties.`statusCode` which contains the status code of the request and `body` that holds the result set from the query. For a full overview of search parameters, check the [documentation](https://github.com/cbmjs/cbm-engine/blob/master/docs/CALLBYMEANING.md).
82
82
83
83
Example code:
84
84
@@ -91,7 +91,7 @@ cbm.call({
91
91
'inputVars': bday,
92
92
'outputConcepts':'time',
93
93
'outputUnits':'seconds'
94
-
}.then((result) => {
94
+
}).then((result) => {
95
95
if (result.statusCode===200) console.log('Success!');
96
96
// insert code here
97
97
}).catch((error) =>console.error(error));
@@ -102,19 +102,21 @@ cbm.call('date', null, 'time', 'seconds', true).then(...); // If we want the sou
102
102
103
103
### `.getCode(fileName)`
104
104
105
-
This method acts as a small helper to the usage of `.search` and `.call` methods. It takes the `name` of a .js file in the server and returns its code in plain text.
105
+
This method acts as a small helper to the usage of `.search` and `.call` methods. It takes the `name` of a .js file in the server and returns its code in plain text.This method is asynchronous and returns a promise that, when fulfilled, returns a string containing the code.
106
106
107
107
Example code:
108
108
109
109
```javascript
110
-
let code =cbm.getCode('getTime.js');
111
-
constgetTime=eval(code);
112
-
getTime();
110
+
cbm.getCode('getTime.js').then(code=> {
111
+
constgetTime=eval(code);
112
+
getTime();
113
+
});
114
+
113
115
```
114
116
115
117
## `.create(params[, type])`
116
118
117
-
This method creates a document in the server if it doesn't exist or modifies it, if it does. It accepts a [params](https://github.com/cbmjs/CallByMeaning/blob/master/docs/MODELS.md) object with the document parameters as its first argument and a string containing the type of the document. It can be one of `concept`, `function`, `relation`. If it isn't provided, it defaults to `concept`. This method is asynchronous and returns a promise that, when fulfilled, returns a boolean, depending of its success.
119
+
This method creates a document in the server if it doesn't exist or modifies it, if it does. It accepts a [params](https://github.com/cbmjs/cbm-engine/blob/master/docs/MODELS.md) object with the document parameters as its first argument and a string containing the type of the document. It can be one of `concept`, `function`, `relation`. If it isn't provided, it defaults to `concept`. This method is asynchronous and returns a promise that, when fulfilled, returns a boolean, depending of its success.
0 commit comments