Notice: All functions throw exceptions in case of fatal errors.
You may read the last error with getErrMsg() any time, an empty string indicates no error occured.
See constants used by Scripal library at the end of the document.
Remember to use proper escape sequences and nested strings, depending on the language used.
Example: obj.match("match 't' ")
get library version
string getVersion()
initialize library base once and set path to the Scripal shared library
aLibPath is the entire path to the Scripal shared libary (libscripal.so under Linux, scripal.dll under Windows systems)
baseInit(aLibPath)
finalize library base at end of process (no need to call)
baseFinalize()
initialize library, call on every new process and! for every thread
aConfigPath is the path to the config file to be used, set empty string for default
aEnconding is the charater encoding to be used, set to default to use the language's default, example scripal.ENC_DEFAULT
libInit(string aConfigPath, int aEncoding)
end library process
libFinalize()
initialize logs
aLogChannel is "default" (disable logs), "stdout", "buffer" or path to file
logInit(aLogChannel)
get contents of log buffer
string getLogBuf()
clear log buffer
clearLogBuf()
get last error message
string getErrMsg()
get last explicit error, with more details
string getErrExp()
get last error position
int getErrPos()
clear last error
clearErr()
A Scripal object is based on class TFScripal, constructors are
create new code object form given source
obj TFScripal("source", string aSource)
create new object for nearest match with given source and maximum distance
obj TFScripal("nearest", string aSource, float aMax)
create new object for block match with given source and maximum distance
obj TFScripal("block", string aSource, float aMax)
match object against text
return true if at least one occurence was found
bool obj.match(string aText)
match object against file
return true if at least one occurence was found
aFileEncoding is the character encoding of the file, set to ENC_DEFAULT to guess the encoding
bool obj.matchFile(string aFile, int aFileEncoding)
replace all matched occurences with given string aReplace
return true if at least one occurence was found
bool obj.replace(string aText, string aReplace)
replace all occurences with given string aReplace in aFileIn and write into new file
aFileEncoding is the character encoding of the file, set to ENC_DEFAULT to guess the encoding
return true if at least one occurence was found
bool obj.replaceFile(string aFileIn, string aFileOut, string aReplace, int aFileEncoding)
match against text and split text at given occurences
return true if at least one occurence was found
bool obj.split(string aText)
match against file and split text at given occurences, write to new file aFileOut
aFileEncoding is the character encoding of the file, set to ENC_DEFAULT to guess the encoding
return true if at least one occurence was found
bool obj.splitFile(string fileIn, string aFileOut, int aFileEncoding)
search in many files / directories and collect results
aPath is the directory to serach in, aDirExtension the file extension (use "" to find all files)
set aRecursive to true to look in all subdirectories as well
bool obj.searchFiles(string aPath, string aDirExtension, bool aRecursive)*
every TFScripal object has an object TFResult, all indexeces are in the range 0,1...
TFResult {
fileNames[] -> file name of result, when using searchFiles() method of TFScripal
text[] -> results strings
positions[] -> positions depending on config.posType
ratings[] -> ratings when using nearest or block match, ratings are in the range 0 (no match)...1 (perfect match)
tags[] -> tags set in Scripal source
size() -> no of results
}
access with obj.results.text[i] etc.
results may be exported in the following formats
* result in JSON format
string obj.getResultJSON()
result in human readable format
string obj.getResultHRF()
result in CSV format
string obj.getResultCSV()
The configuration object config is a thread/process based singleton.
set config according to locale
config.setLocale(string aLocale)
get config as JSON string
string config.toJSON()
get config or parts as JSON string
aKeys may be "all" to get the entire config or just parts like "debugRun, debugCompile"
string config.toJSONVal(string aKeys)
set config or only selected parts from JSON string
example: config.fromJSON("{'debugRun' : true}")
config.fromJSON(string aJSON)
store config in given file
config.store(string aFile)
restore config form given file
config.restore(string aFile)
The templates object ist a global singleton, which is thread safe and can be accessed by all processes and threads.
delete template with given name
templates.clear(string aName)
clear all templates
templates.reset()
get template with given name
string templates.get(string aName)
create template with given name
templates.set(string aName, string aSource)
store all templates in given file
template.store(string aFile)
restore all templates form given file
template.restore(string aFile)
get templates as JSON string
template.ToJSON(string aNames)
set templates from JSON string
template.fromJSON(string aJSON)
ENC_DEFAULT = 1 use Locales encoding
ENC_UTF8 = 2 UTF-8
ENC_UTF16L = 3 UTF-16 little-endian
ENC_UTF16B = 4 UTF-16 big-endian
ENC_UTF32L = 5 UTF-32 little-endian
ENC_UTF32B = 6 UTF-32 big-endian
ENC_ASCII = 10 ASCII , Extended ASCII (up to 255)
ENC_CP932 = 11 CP932 DBCS, Japanese characters
ENC_CP936 = 12 CP93 6DBCS, simple Chinese characters
ENC_CP949 = 13 CP949 DBCS, Korean characters
ENC_CP950 = 14 CP505 DBCS, Chinese Big5 characters
ENC_LATIN1 = 30 West Europe Latin-1, ISO 8859-15
ENC_LATIN2 = 31 Middle Europe Latin-2, ISO 8859-15
ENC_LATIN9 = 32 West Europe Latin-9, ISO 8859-15
ENC_WIN874 = 50 Windows Codepage 874, Thai characters
ENC_WIN1250 = 51 Windows Codepage 1251, Middle Europe
ENC_WIN1251 = 52 Windows Codepage 1251, Cyrillic
ENC_WIN1252 = 53 Windows Codepage 1252, West Europe
ENC_WIN1253 = 54 Windows Codepage 1253, Greek
ENC_WIN1254 = 55 Windows Codepage 1254, Turkish
ENC_WIN1255 = 56 Windows Codepage 1255, Hebrew
ENC_WIN1256 = 57 Windows Codepage 1256, Arabic
ENC_WIN1257 = 58 Windows Codepage 1257, Baltic
ENC_WIN1258 = 59 Windows Codepage 1258, Vietnamese
PATTERN_LEVEN_WORD = 1 Levenshtein distance match, use for matching words
PATTERN_LEVENPLUS_WORD = 2 optimized Levenshtein distance match, use for matching words
PATTERN_LEVEN = 3 Levenshtein distance match, use for matching phrases with any characters
PATTERN_JARO = 100 Jaro distance, use for matching phrases and text
PATTERN_JAROWINKLER = 101 Jaro-Winkler distance, use for matching phrases and text
PATTERN_JAROWINKLER_WORD = 102 Jaro-Winkler distance, use for matching words
POS_UTF8 = 1 positions relate to the position in the UTF-8 encoded text
POS_OFFSET = 2 result position relates to character encoding of the text and is byte offset!
POS_COUNT = 3 result position relates to character (UNICODE code point) count