new Categories(config) → {Spyral.Categories}
Construct a new Categories class.
Parameters:
| Name | Type | Description | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
config |
Object | The config object Properties
|
Returns:
Spyral.CategoriesExample
new Spyral.Categories({
categories: {
positive: ['good', 'happy'],
negative: ['bad', 'sad']
},
categoriesRanking: ['positive','negative'],
features: {color: {}},
featureDefaults: {color: '#333333'}
})
Methods
-
addCategory(name)
-
Add a new category.
Parameters:
Name Type Description nameString The category name
-
addFeature(name, defaultValue)
-
Add a feature.
Parameters:
Name Type Description nameString The feature name
defaultValue* The default value
-
addTerm(category, term)
-
Add a term to a category.
Parameters:
Name Type Description categoryString The category name
termString The term
-
addTerms(category, terms)
-
Add multiple terms to a category.
Parameters:
Name Type Description categoryString The category name
termsArray An array of terms
-
getCategories() → {Object}
-
Get the categories.
Returns:
Object -
getCategoriesForTerm(term) → {Array}
-
Get all the categories a term belongs to.
Parameters:
Name Type Description termString The term
Returns:
Array -
getCategoryExportData() → {Object}
-
Get a copy of the category and feature data.
Returns:
Object -
getCategoryFeature(categoryName, featureName) → {*}
-
Get the feature for a category.
Parameters:
Name Type Description categoryNameString The category name
featureNameString The feature name
Returns:
* -
getCategoryForTerm(term) → {string}
-
Get the category that a term belongs to, taking ranking into account.
Parameters:
Name Type Description termString The term
Returns:
string -
getCategoryNames() → {Array}
-
Get category names as an array.
Returns:
Array -
getCategoryRanking(name) → {number}
-
Gets the ranking for a category.
Parameters:
Name Type Description nameString The category name
Returns:
number -
getCategoryTerms(name) → {Array}
-
Get the terms for a category.
Parameters:
Name Type Description nameString The category name
Returns:
Array -
getFeatureForTerm(feature, term) → {*}
-
Get the feature for a term.
Parameters:
Name Type Description featureString The feature
termString The term
Returns:
* -
getFeatures() → {Object}
-
Get the features.
Returns:
Object -
load(config, apiopt) → {Promise.<Object>}
-
Load the categories (if we're in a recognized environment).
In its simplest form this can be used with a single string ID to load:
new Spyral.Categories().load("categories.en.txt")Which is equivalent to:
new Spyral.Categories().load({retrieveResourceId: "categories.en.txt"});Parameters:
Name Type Attributes Description configObject | String an object specifying the parameters (see above)
apiObject <optional>
an object specifying any parameters for the trombone call
Returns:
Promise.<Object> -this first returns a promise and when the promise is resolved it returns this categories object (with the loaded data included)
-
removeCategory(name)
-
Remove a category.
Parameters:
Name Type Description nameString The category name
-
removeFeature(name)
-
Remove a feature.
Parameters:
Name Type Description nameString The feature name
-
removeTerm(category, term)
-
Remove a term from a category.
Parameters:
Name Type Description categoryString The category name
termString The term
-
removeTerms(category, terms)
-
Remove multiple terms from a category.
Parameters:
Name Type Description categoryString The category name
termsArray An array of terms
-
renameCategory(oldName, newName)
-
Rename a category.
Parameters:
Name Type Description oldNameString The old category name
newNameString The new category name
-
save(config, apiopt) → {Promise.<String>}
-
Save the categories (if we're in a recognized environment).
Parameters:
Name Type Attributes Description configObject for the network call (specifying if needed the location of Trombone, etc., see Spyral.Load#trombone
apiObject <optional>
an object specifying any parameters for the trombone call
Returns:
Promise.<String> -this returns a promise which eventually resolves to a string that is the ID reference for the stored categories
-
setCategoryFeature(categoryName, featureName, featureValue)
-
Set the feature for a category.
Parameters:
Name Type Description categoryNameString The category name
featureNameString The feature name
featureValue* The feature value
-
setCategoryRanking(name, ranking)
-
Sets the ranking for a category.
Parameters:
Name Type Description nameString The category name
rankingnumber The category ranking
-
static load(config, apiopt) → {Promise.<Object>}
-
Load categories and return a promise that resolves to a new Spyral.Categories instance.
Parameters:
Name Type Attributes Description configObject | String an object specifying the parameters (see above)
apiObject <optional>
an object specifying any parameters for the trombone call
Returns:
Promise.<Object> -this first returns a promise and when the promise is resolved it returns this categories object (with the loaded data included)