JSON/YAML as Features#
Objectives#
Definitions & Understanding of what JSON (JavaScript Object Notation) and YAML (Yet Another Markup Language) features are and how they can be used.
Prerequisites#
You have successfully installed Howso Engine
Notebook Recipe#
This user guide has its content outlined in the JSON as a Feature Notebook
Concepts & Terminology#
This guide focuses primarily on the concept of JSON/YAML objects as features. We additionally recommend being familiar with the following concepts:
How-To Guide#
Howso Engine can accept JSON and YAML objects as feature values, treating them like any other feature. This can allow more complex objects to be represented than just numbers or strings.
Declaring a Feature as JSON/YAML#
When calling howso.utilities.infer_../basics/feature_attributes()
, a feature can be declared as JSON or YAML by setting
its data_type
attribute.
features = infer_../basics/feature_attributes(
data,
features={"inventory": {"type": "continuous", "data_type": "json"}}
)
Note that the feature’s type
attribute is set normally to either "continuous"
or "nominal"
. For ones
marked as continuous, distance will be computed using a form of edit distance. Otherwise, the normal nominal distance
computation is used.
Once a feature is set as JSON properly, it can be used as if it were any other feature.
Reacting to JSON/YAML Features#
Below are a few code snippets that show how JSON/YAML features can be used in a react:
t.react(
contexts=[[15, "Warlock"]], context_features=["level", "class"],
action_features=["inventory"],
)
t.react(
contexts=[[15, "Warlock"]], context_features=["level", "class"],
action_features=["inventory"],
desired_conviction=25,
)
t.react(
contexts=[["{\"sword\": 1, \"lute\": 1, \"potion\": 2}", 15]],
context_features=["inventory", "level"],
action_features=["class"],
)
Note
Note that, in the above example, the entire JSON is contained within a string and contained quotes within that are escaped.
API References#
howso.utilities.infer_../basics/feature_attributes()