Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
controlled-english
Advanced tools
JavaScript library for generating Controlled English sentences and interacting with backend stores.
$ npm install controlled-english
const CE = require('controlled-english')
const sentences = new CE.Sentences()
sentences
.there_is_a('person', 'John')
.is_a('man')
.has('value', '53', 'age')
.property('is the sibling of', 'person', 'Jill')
sentences
.the('person', 'John')
.has('colour', 'brown', 'hair colour')
.property('owns', 'pet', 'Fluffy')
console.log(sentences.toString())
Running this source code prints the following Controlled English sentences to the console.
there is a person named John that
is a man and
has the value '53' as age and
is the sibling of the person 'Jill'.
the person John
has the colour 'brown' as hair colour and
owns the pet 'Fluffy'.
This text can be saved to a Controlled English backend store using the CE.Store
class.
const store = new CE.Store({
host: 'localhost:8080',
store: 'DEFAULT'
})
store.save(sentences)
.then(result => console.log(result))
.catch(err => console.log('failed', err))
Sentence Properties
These methods return an instance of that sentence type. This allows the addition of properties through method chaining.
sentences
.there_is_a('man', 'John')
.is_a('football fan')
Creating Multiple Sentences
Each time these methods are called a new sentence instance is added to the internal list of sentences. This allows building Controlled English paragraphs from multiple sentences.
sentences
.conceptualise_a('man')
sentences
.there_is_a('man', 'John')
sentences
.the('man', 'John')
conceptualise a ~ man ~ M. there is a man named John. the man John.
New instances of the CE.Sentences
class can be created using the new
keyword.
const sentences = new CE.Sentences()
The instance will maintain a list of Controlled English sentences created through the API. The current source text can be retrieved using the .toString()
method.
const paragraph = sentences.toString()
New concepts can be created using the following methods.
Creates a new concept.
sentences
.conceptualise_a('man')
conceptualise a ~ man ~ M.
Alias of .conceptualise_a
.
Sets the new concept to also have a parent concept.
sentences
.conceptualise_a('man')
.is_a('person')
conceptualise a ~ man ~ M that
is a person.
Alias of .is_a
.
Adds a property to the concept of the form:
sentences
.conceptualise_a('man')
.has('value', 'age')
.has('colour', 'hair colour')
conceptualise a ~ man ~ M that
has the value V as ~ age ~ and
has the colour C as ~ hair colour ~.
Adds a property to the concept of the form:
sentences
.conceptualise_a('man')
.property('is the sibling of', 'person')
conceptualise a ~ man ~ M that
~ is the sibling of ~ the person P.
Adding new sentences to the instance can be achieved using the following methods.
Defines a new instance.
sentences
.there_is_a('person', 'John')
there is a person named 'John'.
Alias of .there_is_a
.
Extends an existing instance.
sentences
.the('person', 'John')
the person 'John'.
Adds new concept to an instance.
sentences
.the('person', 'John')
.is_a('man')
the person 'John'
is a man.
Alias of .is_a
.
Adds a new property of the form:
sentences
.the('person', 'John')
.has('value', '53', 'age')
the person 'John'
has the value '53' as age.
Adds a new property of the form:
sentences
.the('person', 'John')
.property('is the sibling of', 'person', 'Jill')
the person 'John'
is the sibling of the person 'Jill'.
Queries can be constructed using the following methods.
Creates a new query.
sentences
.query('person')
[ person ]
First line of a query setting up the variables.
sentences
.query('person')
.for('V1', 'V2')
[ person ]
for which V1 and V2 is it true
Tests if there is an instance of that concept.
sentences
.query('person')
.for('V1', 'V2')
.there_is_a('person', 'V1')
[ person ]
for which V1 and V2 is it true
( there is a person named V1 )
.
Alias for .there_is_a
.
Tests if an instance has the parent concept.
sentences
.query('man')
.for('V1', 'V2')
.there_is_a('person', 'V1')
.is_a('person', 'V1', 'man')
[ man ]
for which V1 and V2 is it true
( there is a person named V1 ) and
( the person V1 is a man )
.
Alias for .is_a
.
Tests if each of the matching instances has the property.
sentences
.query('age')
.for('V1', 'V2')
.there_is_a('person', 'V1')
.has('person', 'V1', 'value', 'V2', 'age')
[ age ]
for which V1 and V2 is it true
( there is a person named V1 ) and
( the person V1 has the value V2 as age )
.
Tests if each of the matching instances has the property.
sentences
.query('sibling')
.for('V1', 'V2')
.there_is_a('person', 'V1')
.property('person', 'V1', 'is the sibling of', 'person', 'V2')
[ sibling ]
for which V1 and V2 is it true
( there is a person named V1 ) and
( the person V1 is the sibling of the person V2 )
.
Rules can be constructed using the following methods.
Creates a rule.
sentences
.rule('male')
[ 'male' ]
Enter the if statement of the rule.
sentences
.rule('male')
.if()
[ 'male' ]
if
Tests if there is an instance of the concept.
sentences
.rule('male')
.if()
.there_is_a('person', 'V1')
[ 'male' ]
if
( there is a person named V1 )
Alias of .there_is_a
.
Tests if an instance has the parent concept.
sentences
.rule('male')
.if()
.there_is_a('person', 'V1')
.is_a('person', 'V1', 'male')
[ 'male' ]
if
( there is a person named V1 ) and
( the person V1 is male )
Alias of .is_a
.
Test if an instance has the propety.
sentences
.rule('male')
.if()
.there_is_a('person', 'V1')
.has('person', 'V1', 'value', 'V1', 'age')
[ 'male' ]
if
( there is a person named V1 ) and
( the person V1 has the value V2 as age )
Test if an instance doesn't have the propety.
Can only be used in the if statement
sentences
.rule('male')
.if()
.there_is_a('person', 'V1')
.has_no('person', 'V1', 'value', 'V1', 'age')
[ 'male' ]
if
( there is a person named V1 ) and
( the person V1 has no value V2 as age )
Test if an instance has the property.
sentences
.rule('male')
.if()
.there_is_a('person', 'V1')
.property('person', 'V1', 'is the sibling of', 'person', 'V2')
[ 'male' ]
if
( there is a person named V1 ) and
( the person V1 is the sibling of the person V2 )
Test if an instance has the property.
Can only be used in the if statement
sentences
.rule('male')
.if()
.there_is_a('person', 'V1')
.property_no('person', 'V1', 'is the sibling of', 'person', 'V2')
[ 'male' ]
if
( there is a person named V1 ) and
( the person V1 is the sibling of no person V2 )
Enter the then statement of the rule
sentences
.rule('male')
.if()
.there_is_a('person', 'V1')
.then()
.is_a('person', 'V1', 'human')
[ 'male' ]
if
( there is a person named V1 )
then
( the person V1 is a human )
.
The CE.Store
class is a utility class to help you to save Controlled English sentences to a backend store.
const store = new CE.Store({
host: 'localhost:8080',
store: 'DEFAULT'
})
const sentences = new CE.Sentences()
sentences
.there_is_a('man', 'James')
store.save(sentences)
.then(result => console.log(result))
.catch(err => console.log('failed', err))
store.save("there is a person named James.")
.then(result => console.log(result))
.catch(err => console.log('failed', err))
The save()
method will call the toString()
on the function parameter. This is present on the CE.Sentences
class and also on JavaScript strings.
FAQs
Controlled English JavaScript Client Library
The npm package controlled-english receives a total of 1 weekly downloads. As such, controlled-english popularity was classified as not popular.
We found that controlled-english demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.