Class ScriptedClassifierUtils


  • public class ScriptedClassifierUtils
    extends Object
    Helper class for managing/updating scripts of classifiers that implement ScriptedClassifier.
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    • Constructor Detail

      • ScriptedClassifierUtils

        public ScriptedClassifierUtils()
    • Method Detail

      • initPrediction

        public static int initPrediction​(Object obj,
                                         Actor context)
        Initializes any ScriptedClassifier within the specified object.
        Parameters:
        obj - the object to traverse
        context - the context to use for initialization
        Returns:
        the number of initializations
      • determineUniqueID

        public static String determineUniqueID​(AbstractAdvancedScript script,
                                               String placeholder,
                                               boolean prefix,
                                               boolean update)
        Determines the unique ID (suffix/prefix) to use in the script, if the specified placeholder for the unique ID is present.
        Parameters:
        script - the script to inspect and update
        placeholder - the placeholder that triggers the unique ID generation
        prefix - whether to generate prefix or suffix
        update - whether to replace the placeholder with the unique ID immediately
        Returns:
        the generated unique ID, empty string if not required
      • expand

        public static <T extends AbstractAdvancedScript> T expand​(T script,
                                                                  Actor context)
        Expands flow variables and placeholders in the script.
        Parameters:
        script - the script to expand
        context - the flow context
        Returns:
        the expanded script
      • expand

        protected static ScriptedClassifier expand​(ScriptedClassifier cls,
                                                   PropertyDescriptor desc,
                                                   String[] placeholders,
                                                   String[] values)
                                            throws Exception
        Updates the placeholders with the specified values for the given property.
        Parameters:
        cls - the classifier to update
        desc - the property to update
        placeholders - the placeholders to replace
        values - the replacement values
        Returns:
        the updated classifier
        Throws:
        Exception - if updating fails
      • expand

        public static ScriptedClassifier expand​(ScriptedClassifier cls,
                                                String placeholder,
                                                String value)
                                         throws Exception
        Replaces the placeholder with the specified value in any AbstractAdvancedScript property of the classifier.
        Parameters:
        cls - the classifier to update
        placeholder - the placeholder to replace
        value - the replacement value
        Returns:
        the updated classifier
        Throws:
        Exception - if introspection or updating of scripts fails
      • expand

        public static ScriptedClassifier expand​(ScriptedClassifier cls,
                                                String[] placeholders,
                                                String[] values)
                                         throws Exception
        Replaces the placeholder with the specified value in any AbstractAdvancedScript property of the classifier.
        Parameters:
        cls - the classifier to update
        placeholders - the placeholder to replace
        values - the replacement value
        Returns:
        the updated classifier
        Throws:
        Exception - if introspection or updating of scripts fails