Next: , Up: (dir)

String NodeBrain Module

This manual is for the String NodeBrain Module (version 0.2, August 2014) used for string manipulation.

Copyright © 2014 Ed Trettevik <eat@nodebrain.org>

Permission is granted to copy, distribute and/or modify this document under the terms of either the MIT License (Expat) or NodeBrain License. See the Licenses section at the end of this document for details.
Short Table Of Contents

Table of Contents


Next: , Previous: Top, Up: Top

1 Concepts

The String module implements nodes that manipulate strings in some way. This is initially a very minimal set of evaluation methods. NodeBrain is not intended to perform string manipulation with the goal of producing output for human consumption. However, it is helpful to have some string manipulation capability to consume text representations of events. Regular expressions provide the functionality needed to extract information from text. Once extracted, we sometimes need to transform the extracted strings. In general, it is best to delegate this function to servants using your favorate string manipulation language. But where we see a repeating need for a simple string manipulation, additional skills will be added to this module.

Regular expression based substitution supported by the PCRE library will most likely be included in the language in a future release. The operations provided by this module are expected to be less complex and more special purpose.


Next: , Previous: Concepts, Up: Top

2 Tutorial

Generosity with strings is not generosity; It is a deal. —Marya Mannes

Here's the deal with NodeBrain strings. Translators and regular expressions are used to recognize and take strings apart and symbolic substitution is used to construct new strings. Tree nodes can be used to translate strings by looking up one string and substituting another. But that's about the limit of NodeBrain's generosity with strings. The string module exists to enable additional string manipulation capability as needed to digest input event attributes for processing with rules. So far, little has been needed, and this is a trivial module.

The following example illustrates how a string.utc node can be used to transform a time stamp in a broken down format into a UTC time string. This transformation is based on the strptime C function.

     > define utc node string.utc;
     > define whenUtc cell utc(when,"%Y-%m-%d %H:%M:%S");
     > assert when="2012-06-19 10:20:35";
     > assert x=whenUtc; # force evaluation of whenUtc since there is no rule depending on it
     > show x;
     x = "1340101235"
     > assert when="2012-05-12 12:15:50";
     > assert x=whenUtc;
     > show x;
     x = "1336824950"


The next example might apply in a case where a string value is to be used in an output alarm passed to an application where ";" has a special meaning. A string.chrsub node is used to substitute a "," for any ";" in the string.

     > define chrsub node string.chrsub;
     > define clean cell chrsub(dirty,";,");
     > assert dirty="There is always hope; at least for now.";
     > assert x=clean; # force evaluation of clean since there is no rule depending on it
     > show x;
     x = "There is always hope, at least for now."


Next: , Previous: Tutorial, Up: Top

3 Commands

This section describes commands used with a String node.

3.1 Define

The define command is used to create String manipulation nodes. Although any term can be defined for a String node, using the skill name for the term is generally a good idea.

Syntax

chrsubDefineCmd ::= define s* chrsub s* node s* string.chrsub [ ; ] •
utcDefineCmd ::= define s* utc s* node s* string.utc [ ; ] •

3.2 Cell Evaluation

String manipulation cells use String nodes to perform operations on string operands and/or produce strings.

Syntax

chrsubCell ::= chrsub( string , pairString )
utcCell ::= utc( timestring , formatstring )

3.2.1 chrsub

The chrsub node substitutes one character for another in a string.

     strsub(text,"xy")    # character x replaces y
     strsub(text,"xyab")  # character x replaces y and a replaced b

3.2.2 utc

The utc node converts a time string into UTC time. See the man page for strptime for a description of the format string.

     utc("2001-11-12 18:31:01","%Y-%m-%d %H:%M:%S")
     utc(mytimestamp,"%Y-%m-%d %H:%M:%S")

3.3 Assert

Assertions are not supported by this module.

3.4 Node Commands

This module does not implement node commands.

3.5 Module Commands

This module does not implement module commands.


Next: , Previous: Commands, Up: Top

4 Triggers

This module does not implement triggers.


Next: , Previous: Triggers, Up: Top

Licenses

NodeBrain is free software; you can modify and/or redistribute it, including this document, under the terms of either the MIT License (Expat) or the NodeBrain License.


MIT License

Copyright © 2014 Ed Trettevik <eat@nodebrain.org>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


NodeBrain License

Copyright © 2014 Ed Trettevik <eat@nodebrain.org>

Permission to use and redistribute with or without fee, in source and binary forms, with or without modification, is granted free of charge to any person obtaining a copy of this software and included documentation, provided that the above copyright notice, this permission notice, and the following disclaimer are retained with source files and reproduced in documention included with source and binary distributions.

Unless required by applicable law or agreed to in writing, this software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.


Previous: Licenses, Up: Top

Index