The Expression class is one of the four core classes in the sfutils package. An Expression is more complicated than a Term or a Text because one can define operations (subtract, add) on them.
Expression(expression, ...)
expression | expression to be fingerprinted |
---|---|
... | other options to be passed (uuid, fingerprint) |
(From http://documentation.cortical.io/the_power_of_expressions.html) As briefly mentioned in the introduction, semantically meaningful operations can be carried out on fingerprints by performing simple binary operations on the positions of the fingerprints. Semantic relationships between fingerprints can be discovered by looking at their overlapping positions in the semantic space. This allows us, for example, to subtract the meaning of one term from the meaning of another term to obtain a more specific representation. In the /expressions endpoint, we offer these binary operations on the fingerprints and, along with this, a flexible way of specifying the input data.
expression
expression to be fingerprinted
fingerprint
numeric vector of the fingerprint
See the Cortical documentation for more information about semantic fingerprinting and expressions
# NOT RUN { ##### Single expression # Expressions work with texts and terms # They require a specific format # For a single expression, the input must be a list # With named entries, for example: ex1_body <- list( "term" = "Finance" ) # Fingerprint ex1_fp <- do_fingerprint_expression(ex1_body) # You can combine this with e.g. subtractions: ex2_body <- list( "term" = "Finance", "sub" = list( "term" = "Market", "positions" = c(2,6,4) ) ) # Fingerprint ex2_body <- do_fingerprint_expression(ex2_body) # Plot the difference plot(ex1_fp, ex2_fp) ###### MULTIPLE EXPRESSIONS # The input must be an unnamed list, each entry # Of which is also a list with named entries. # For example, if you want to fingerprint a term # As an expression, do: ex3_body <- list( list( "term" = "Finance" ), list( "term" = "Finance", "sub" = list( "term" = "Market", "positions" = c(2,6,4) ) ) ) # This will return a Collection # Fingerprint ex3_fp <- do_fingerprint_expression(ex3_body) # }