Java Code Examples for org.antlr.runtime.tree.Tree#getChildCount()

The following examples show how to use org.antlr.runtime.tree.Tree#getChildCount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FunctionBlock.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Parse a tree for singletons membership function series of points
 * @param tree : Tree to parse
 * @param numberOfPoints : Number of points in this function
 * @return A new membership function
 */
private MembershipFunction fclTreeFuzzifyTermSingletonsPoints(Tree tree, int numberOfPoints) {
	if (debug) Gpr.debug("Tree: " + tree.toStringTree());

	Value x[] = new Value[numberOfPoints];
	Value y[] = new Value[numberOfPoints];
	for (int childNum = 0; childNum < tree.getChildCount(); childNum++) {
		Tree child = tree.getChild(childNum);
		String leaveName = child.getText();
		if (debug) Gpr.debug("Sub-Parsing: " + leaveName);

		// It's a set of points? => Defines a piece-wise linear membership function
		if (leaveName.equalsIgnoreCase("(")) {
			x[childNum] = new Value(child.getChild(0), this); // Parse and add each point
			y[childNum] = new Value(child.getChild(1), this);

			if ((y[childNum].getValue() < 0) || (y[childNum].getValue() > 1)) throw new RuntimeException("\n\tError parsing line " + child.getLine() + " character " + child.getCharPositionInLine() + ": Membership function out of range (should be between 0 and 1). Value: '" + y[childNum] + "'\n\tTree: " + child.toStringTree());

			if (debug) Gpr.debug("Parsed point " + childNum + " x=" + x[childNum] + ", y=" + y[childNum]);
		} else throw new RuntimeException("Unknown (or unimplemented) option : " + leaveName);
	}
	return new MembershipFunctionGenericSingleton(x, y);
}
 
Example 2
Source File: RuleBlock.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Parse rule Implication Method (or rule activation method)
 * @param tree : Tree to parse
 */
private void fclTreeRuleBlockRule(Tree tree, RuleConnectionMethod and, RuleConnectionMethod or) {
	if (debug) Gpr.debug("Tree: " + tree.toStringTree());
	Rule fuzzyRule = new Rule(tree.getChild(0).getText(), this);

	for (int childNum = 1; childNum < tree.getChildCount(); childNum++) {
		Tree child = tree.getChild(childNum);
		if (debug) Gpr.debug("\t\tChild: " + child.toStringTree());
		String type = child.getText();

		if (type.equalsIgnoreCase("IF")) fuzzyRule.setAntecedents(fclTreeRuleBlockRuleIf(child.getChild(0), and, or));
		else if (type.equalsIgnoreCase("THEN")) fclTreeRuleBlockRuleThen(child, fuzzyRule);
		else if (type.equalsIgnoreCase("WITH")) fclTreeRuleBlockRuleWith(child, fuzzyRule);
		else throw new RuntimeException("Unknown (or unimplemented) rule block item: " + type);
	}

	add(fuzzyRule);
}
 
Example 3
Source File: HL7Query.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private void processDeclare(final Tree declare) {
    for (int i = 0; i < declare.getChildCount(); i++) {
        final Tree declarationTree = declare.getChild(i);

        final String identifier = declarationTree.getChild(0).getText();
        final Tree requiredOrOptionalTree = declarationTree.getChild(1);
        final boolean required = requiredOrOptionalTree.getType() == REQUIRED;

        final String segmentName = declarationTree.getChild(2).getText();

        final Declaration declaration = new Declaration() {
            @Override
            public String getAlias() {
                return identifier;
            }

            @Override
            public boolean isRequired() {
                return required;
            }

            @Override
            public Object getDeclaredValue(final HL7Message message) {
                if (message == null) {
                    return null;
                }

                return message.getSegments(segmentName);
            }
        };

        declarations.add(declaration);
    }
}
 
Example 4
Source File: RuleBlock.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Parse rule 'THEN' (or rule's weight)
 * @param tree : Tree to parse
 */
private void fclTreeRuleBlockRuleThen(Tree tree, Rule fuzzyRule) {
	if (debug) Gpr.debug("Tree: " + tree.toStringTree());

	for (int childNum = 0; childNum < tree.getChildCount(); childNum++) {
		Tree child = tree.getChild(childNum);
		if (debug) Gpr.debug("\t\tChild: " + child.toStringTree());
		String thenVariable = child.getText();

		String thenValue = child.getChild(0).getText();
		Variable variable = getVariable(thenVariable);
		if (variable == null) throw new RuntimeException("Variable " + thenVariable + " does not exist");
		fuzzyRule.addConsequent(variable, thenValue, false);
	}
}
 
Example 5
Source File: RecordPathCompiler.java    From nifi with Apache License 2.0 5 votes vote down vote up
private static RecordPathSegment[] getArgPaths(final Tree argumentListTree, final int minCount, final int maxCount, final String functionName, final boolean absolute) {
    final int numArgs = argumentListTree.getChildCount();
    if (numArgs < minCount || numArgs > maxCount) {
        throw new RecordPathException("Invalid number of arguments: " + functionName + " function takes at least" + minCount
                + " arguments, and at most " + maxCount + "arguments, but got " + numArgs);
    }

    final List<RecordPathSegment> argPaths = new ArrayList<>();
    for (int i=0; i < argumentListTree.getChildCount(); i++) {
        argPaths.add(buildPath(argumentListTree.getChild(i), null, absolute));
    }

    return argPaths.toArray(new RecordPathSegment[argPaths.size()]);
}
 
Example 6
Source File: RecordPathCompiler.java    From nifi with Apache License 2.0 5 votes vote down vote up
private static RecordPathSegment[] getArgPaths(final Tree argumentListTree, final int expectedCount, final String functionName, final boolean absolute) {
    final int numArgs = argumentListTree.getChildCount();
    if (numArgs != expectedCount) {
        throw new RecordPathException("Invalid number of arguments: " + functionName + " function takes " + expectedCount + " arguments but got " + numArgs);
    }

    final RecordPathSegment[] argPaths = new RecordPathSegment[expectedCount];
    for (int i = 0; i < expectedCount; i++) {
        argPaths[i] = buildPath(argumentListTree.getChild(i), null, absolute);
    }

    return argPaths;
}
 
Example 7
Source File: FunctionBlock.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Parse a tree for "Fuzzify" item
 * @param tree : Tree to parse
 * @return Variable (old or created)
 */
private Variable fclTreeFuzzify(Tree tree) {
	Gpr.checkRootNode("FUZZIFY", tree);
	if (debug) Gpr.debug("Tree: " + tree.toStringTree());
	Tree child = tree.getChild(0);
	String varName = child.getText();

	// Get variable (or create a new one)
	Variable variable = getVariable(varName);
	if (variable == null) {
		variable = new Variable(varName);
		setVariable(varName, variable);
		if (debug) Gpr.debug("Variable '" + varName + "' does not exist => Creating it");
	}

	// Explore each sibling in this level
	for (int childNum = 1; childNum < tree.getChildCount(); childNum++) {
		child = tree.getChild(childNum);
		if (debug) Gpr.debug("\t\tChild: " + child.toStringTree());
		String leaveName = child.getText();

		if (leaveName.equalsIgnoreCase("TERM")) {
			LinguisticTerm linguisticTerm = fclTreeFuzzifyTerm(child, variable);
			variable.add(linguisticTerm);
		} else throw new RuntimeException("Unknown/Unimplemented item '" + leaveName + "'");
	}

	return variable;
}
 
Example 8
Source File: HL7Query.java    From nifi with Apache License 2.0 5 votes vote down vote up
private String getSelectedName(final Tree selectable) {
    if (selectable.getChildCount() == 0) {
        return selectable.getText();
    } else if (selectable.getType() == DOT) {
        return getSelectedName(selectable.getChild(0)) + "." + getSelectedName(selectable.getChild(1));
    } else {
        return selectable.getChild(selectable.getChildCount() - 1).getText();
    }
}
 
Example 9
Source File: RecordPathCompiler.java    From nifi with Apache License 2.0 5 votes vote down vote up
private static RecordPathSegment[] getArgumentsForStringFunction(boolean absolute, Tree argumentListTree) {
    final int numArgs = argumentListTree.getChildCount();

    final RecordPathSegment[] argPaths = new RecordPathSegment[numArgs];
    for (int i = 0; i < numArgs; i++) {
        argPaths[i] = buildPath(argumentListTree.getChild(i), null, absolute);
    }

    return argPaths;
}
 
Example 10
Source File: TestQuery.java    From nifi with Apache License 2.0 5 votes vote down vote up
private void printTree(final Tree tree, final int spaces, final StringBuilder sb) {
    for (int i = 0; i < spaces; i++) {
        sb.append(" ");
    }

    if (tree.getText().trim().isEmpty()) {
        sb.append(tree.toString()).append("\n");
    } else {
        sb.append(tree.getText()).append("\n");
    }

    for (int i = 0; i < tree.getChildCount(); i++) {
        printTree(tree.getChild(i), spaces + 2, sb);
    }
}
 
Example 11
Source File: FIS.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Create a "Fuzzy inference system (FIS)" from an FCL definition string
 * @param lexer : lexer to use
 * @param verbose : be verbose?
 * @return A new FIS (or null on error)
 */
private static FIS createFromLexer(FclLexer lexer, boolean verbose) throws RecognitionException {
	FIS fis = new FIS();
	CommonTokenStream tokens = new CommonTokenStream(lexer);
	FclParser parser = new FclParser(tokens);

	// FclParser.fcl_return root = parser.fcl();
	FclParser.main_return root;
	root = parser.main();
	Tree parseTree = (Tree) root.getTree();

	// Error loading file?
	if (parseTree == null) {
		System.err.println("Can't create FIS");
		return null;
	}

	if (debug) Gpr.debug("Tree: " + parseTree.toStringTree());

	// Add every FunctionBlock (there may be more than one in each FCL file)
	for (int childNum = 0; childNum < parseTree.getChildCount(); childNum++) {
		Tree child = parseTree.getChild(childNum);
		if (debug) Gpr.debug("Child " + childNum + ":\t" + child + "\tTree:'" + child.toStringTree() + "'");

		// Create a new FunctionBlock
		FunctionBlock functionBlock = new FunctionBlock(fis);

		// Generate fuzzyRuleSet based on tree
		String name = functionBlock.fclTree(child);
		if (debug) Gpr.debug("FunctionBlock Name: '" + name + "'");
		fis.addFunctionBlock(name, functionBlock);
	}

	return fis;
}
 
Example 12
Source File: HL7Query.java    From nifi with Apache License 2.0 5 votes vote down vote up
private void processDeclare(final Tree declare) {
    for (int i = 0; i < declare.getChildCount(); i++) {
        final Tree declarationTree = declare.getChild(i);

        final String identifier = declarationTree.getChild(0).getText();
        final Tree requiredOrOptionalTree = declarationTree.getChild(1);
        final boolean required = requiredOrOptionalTree.getType() == REQUIRED;

        final String segmentName = declarationTree.getChild(2).getText();

        final Declaration declaration = new Declaration() {
            @Override
            public String getAlias() {
                return identifier;
            }

            @Override
            public boolean isRequired() {
                return required;
            }

            @Override
            public Object getDeclaredValue(final HL7Message message) {
                if (message == null) {
                    return null;
                }

                return message.getSegments(segmentName);
            }
        };

        declarations.add(declaration);
    }
}
 
Example 13
Source File: TestQuery.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private void printTree(final Tree tree, final int spaces, final StringBuilder sb) {
    for (int i = 0; i < spaces; i++) {
        sb.append(" ");
    }

    if (tree.getText().trim().isEmpty()) {
        sb.append(tree.toString()).append("\n");
    } else {
        sb.append(tree.getText()).append("\n");
    }

    for (int i = 0; i < tree.getChildCount(); i++) {
        printTree(tree.getChild(i), spaces + 2, sb);
    }
}
 
Example 14
Source File: CliClient.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
/**
 * Used to get Map of the provided options by create/update keyspace commands
 * @param options - tree representing options
 * @return Map - strategy_options map
 */
private Map<String, String> getStrategyOptionsFromTree(Tree options)
{
    //Check for old [{}] syntax
    if (options.getText().equalsIgnoreCase("ARRAY"))
    {
        System.err.println("WARNING: [{}] strategy_options syntax is deprecated, please use {}");

        if (options.getChildCount() == 0)
            return Collections.EMPTY_MAP;

        return getStrategyOptionsFromTree(options.getChild(0));
    }

    // this map will be returned
    Map<String, String> strategyOptions = new HashMap<String, String>();

    // each child node is ^(PAIR $key $value)
    for (int j = 0; j < options.getChildCount(); j++)
    {
        Tree optionPair = options.getChild(j);

        // current $key
        String key = CliUtils.unescapeSQLString(optionPair.getChild(0).getText());
        // current $value
        String val = CliUtils.unescapeSQLString(optionPair.getChild(1).getText());

        strategyOptions.put(key, val);
    }

    return strategyOptions;
}
 
Example 15
Source File: RecordPathCompiler.java    From nifi with Apache License 2.0 5 votes vote down vote up
public static RecordPathSegment compile(final Tree pathTree, final RecordPathSegment root, final boolean absolute) {
    if (pathTree.getType() == FUNCTION) {
        return buildPath(pathTree, null, absolute);
    }

    RecordPathSegment parent = root;
    for (int i = 0; i < pathTree.getChildCount(); i++) {
        final Tree child = pathTree.getChild(i);
        parent = RecordPathCompiler.buildPath(child, parent, absolute);
    }

    return parent;
}
 
Example 16
Source File: HL7Query.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private List<Selection> processSelect(final Tree select) {
    final List<Selection> selections = new ArrayList<>();

    for (int i = 0; i < select.getChildCount(); i++) {
        final Tree selectable = select.getChild(i);

        final String alias = getSelectedName(selectable);
        final Evaluator<?> selectionEvaluator = buildReferenceEvaluator(selectable);
        final Selection selection = new Selection(selectionEvaluator, alias);
        selections.add(selection);
    }

    return selections;
}
 
Example 17
Source File: Query.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
private static Evaluator<?> buildExpressionEvaluator(final Tree tree) {
    if (tree.getChildCount() == 0) {
        throw new AttributeExpressionLanguageParsingException("EXPRESSION tree node has no children");
    }

    final Evaluator<?> evaluator;
    if (tree.getChildCount() == 1) {
        evaluator = buildEvaluator(tree.getChild(0));
    } else {
        // we can chain together functions in the form of:
        // ${x:trim():substring(1,2):trim()}
        // in this case, the subject of the right-most function is the function to its left; its
        // subject is the function to its left (the first trim()), and its subject is the value of
        // the 'x' attribute. We accomplish this logic by iterating over all of the children of the
        // tree from the right-most child going left-ward.
        evaluator = buildFunctionExpressionEvaluator(tree, 0);
    }

    Evaluator<?> chosenEvaluator = evaluator;
    final Evaluator<?> rootEvaluator = getRootSubjectEvaluator(evaluator);
    if (rootEvaluator != null) {
        if (rootEvaluator instanceof MultiAttributeEvaluator) {
            final MultiAttributeEvaluator multiAttrEval = (MultiAttributeEvaluator) rootEvaluator;

            switch (multiAttrEval.getEvaluationType()) {
                case ANY_ATTRIBUTE:
                case ANY_MATCHING_ATTRIBUTE:
                case ANY_DELINEATED_VALUE:
                    chosenEvaluator = new AnyAttributeEvaluator((BooleanEvaluator) evaluator, multiAttrEval);
                    break;
                case ALL_ATTRIBUTES:
                case ALL_MATCHING_ATTRIBUTES:
                case ALL_DELINEATED_VALUES: {
                    final ResultType resultType = evaluator.getResultType();
                    if (resultType == ResultType.BOOLEAN) {
                        chosenEvaluator = new AllAttributesEvaluator((BooleanEvaluator) evaluator, multiAttrEval);
                    } else if (evaluator instanceof ReduceEvaluator) {
                        chosenEvaluator = new MappingEvaluator((ReduceEvaluator) evaluator, multiAttrEval);
                    } else {
                        throw new AttributeExpressionLanguageException("Cannot evaluate Expression because it attempts to reference multiple attributes but does not use a reducing function");
                    }
                    break;
                }
            }

            switch (multiAttrEval.getEvaluationType()) {
                case ANY_ATTRIBUTE:
                    chosenEvaluator.setToken("anyAttribute");
                    break;
                case ANY_MATCHING_ATTRIBUTE:
                    chosenEvaluator.setToken("anyMatchingAttribute");
                    break;
                case ANY_DELINEATED_VALUE:
                    chosenEvaluator.setToken("anyDelineatedValue");
                    break;
                case ALL_ATTRIBUTES:
                    chosenEvaluator.setToken("allAttributes");
                    break;
                case ALL_MATCHING_ATTRIBUTES:
                    chosenEvaluator.setToken("allMatchingAttributes");
                    break;
                case ALL_DELINEATED_VALUES:
                    chosenEvaluator.setToken("allDelineatedValues");
                    break;
            }
        }
    }

    return chosenEvaluator;
}
 
Example 18
Source File: CliClient.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
/**
 * Used to parse meta tree and compile meta attributes into List<ColumnDef>
 * @param cfDef - column family definition
 * @param meta (Tree representing Array of the hashes with metadata attributes)
 * @return List<ColumnDef> List of the ColumnDef's
 *
 * meta is in following format - ^(ARRAY ^(HASH ^(PAIR .. ..) ^(PAIR .. ..)) ^(HASH ...))
 */
private List<ColumnDef> getCFColumnMetaFromTree(CfDef cfDef, Tree meta)
{
    // this list will be returned
    List<ColumnDef> columnDefinitions = new ArrayList<ColumnDef>();

    // each child node is a ^(HASH ...)
    for (int i = 0; i < meta.getChildCount(); i++)
    {
        Tree metaHash = meta.getChild(i);

        ColumnDef columnDefinition = new ColumnDef();

        // each child node is ^(PAIR $key $value)
        for (int j = 0; j < metaHash.getChildCount(); j++)
        {
            Tree metaPair = metaHash.getChild(j);

            // current $key
            String metaKey = CliUtils.unescapeSQLString(metaPair.getChild(0).getText());
            // current $value
            String metaVal = CliUtils.unescapeSQLString(metaPair.getChild(1).getText());

            if (metaKey.equals("column_name"))
            {
                if (cfDef.column_type.equals("Super"))
                    columnDefinition.setName(subColumnNameAsByteArray(metaVal, cfDef));
                else
                    columnDefinition.setName(columnNameAsByteArray(metaVal, cfDef));
            }
            else if (metaKey.equals("validation_class"))
            {
                columnDefinition.setValidation_class(metaVal);
            }
            else if (metaKey.equals("index_type"))
            {
                columnDefinition.setIndex_type(getIndexTypeFromString(metaVal));
            }
            else if (metaKey.equals("index_options"))
            {
                columnDefinition.setIndex_options(getStrategyOptionsFromTree(metaPair.getChild(1)));
            }
            else if (metaKey.equals("index_name"))
            {
                columnDefinition.setIndex_name(metaVal);
            }
            else
            {
                throw new RuntimeException("Unsupported column_metadata pair given => " + metaKey + ": " + metaVal);
            }
        }

        // validating columnDef structure, 'name' and 'validation_class' must be set
        try
        {
            columnDefinition.validate();
        }
        catch (TException e)
        {
            throw new RuntimeException(e);
        }

        columnDefinitions.add(columnDefinition);
    }

    return columnDefinitions;
}
 
Example 19
Source File: FunctionBlock.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Parse a tree for "Defuzzify" item
 * @param tree : Tree to parse
 * @return Variable (old or created)
 */
private Variable fclTreeDefuzzify(Tree tree) {
	Gpr.checkRootNode("DEFUZZIFY", tree);
	if (debug) Gpr.debug("Tree: " + tree.toStringTree());
	String defuzzificationMethodType = "COG";

	Tree child = tree.getChild(0);
	String varName = child.getText();

	// Get variable (or create a new one)
	Variable variable = getVariable(varName);
	if (variable == null) {
		variable = new Variable(varName);
		setVariable(varName, variable);
		if (debug) Gpr.debug("Variable '" + varName + "' does not exist => Creating it");
	}

	//---
	// Explore each sibling in this level
	//---
	for (int childNum = 1; childNum < tree.getChildCount(); childNum++) {
		child = tree.getChild(childNum);
		String leaveName = child.getText();
		if (debug) Gpr.debug("\t\tChild: " + child.toStringTree());

		if (leaveName.equalsIgnoreCase("TERM")) {
			// Linguistic term
			LinguisticTerm linguisticTerm = fclTreeFuzzifyTerm(child, variable);
			variable.add(linguisticTerm);
		} else if (leaveName.equalsIgnoreCase("ACCU")) // Accumulation method
			throw new RuntimeException("Accumulation method (ACCU) must be defined at RULE_BLOCK");
		// ruleAccumulationMethodType = child.getChild(0).getText();
		else if (leaveName.equalsIgnoreCase("METHOD")) // Defuzzification method
			defuzzificationMethodType = child.getChild(0).getText();
		else if (leaveName.equalsIgnoreCase("DEFAULT")) {
			// Default value
			String defaultValueStr = child.getChild(0).getText();
			if (defaultValueStr.equalsIgnoreCase("NC")) variable.setDefaultValue(Double.NaN); // Set it to "No Change"?
			else variable.setDefaultValue(Gpr.parseDouble(child.getChild(0))); // Set value
		} else if (leaveName.equalsIgnoreCase("RANGE")) {
			// Range values (universe min / max)
			double universeMin = Gpr.parseDouble(child.getChild(0));
			double universeMax = Gpr.parseDouble(child.getChild(1));
			if (universeMax <= universeMin) throw new RuntimeException("Range's min is grater than range's max! RANGE := ( " + universeMin + " .. " + universeMax + " );");
			variable.setUniverseMax(universeMax);
			variable.setUniverseMin(universeMin);
		} else throw new RuntimeException("Unknown/Unimplemented item '" + leaveName + "'");
	}

	// Defuzzification method
	Defuzzifier defuzzifier = createDefuzzifier(defuzzificationMethodType, variable);
	variable.setDefuzzifier(defuzzifier);

	return variable;
}
 
Example 20
Source File: CliClient.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
/**
 * Used to update keyspace definition attributes
 * @param statement - ANTRL tree representing current statement
 * @param ksDefToUpdate - keyspace definition to update
 * @return ksDef - updated keyspace definition
 */
private KsDef updateKsDefAttributes(Tree statement, KsDef ksDefToUpdate)
{
    KsDef ksDef = new KsDef(ksDefToUpdate);

    // removing all column definitions - thrift system_update_keyspace method requires that
    ksDef.setCf_defs(new LinkedList<CfDef>());

    for(int i = 1; i < statement.getChildCount(); i += 2)
    {
        String currentStatement = statement.getChild(i).getText().toUpperCase();
        AddKeyspaceArgument mArgument = AddKeyspaceArgument.valueOf(currentStatement);
        String mValue = statement.getChild(i + 1).getText();

        switch(mArgument)
        {
        case PLACEMENT_STRATEGY:
            ksDef.setStrategy_class(CliUtils.unescapeSQLString(mValue));
            break;
        case STRATEGY_OPTIONS:
            ksDef.setStrategy_options(getStrategyOptionsFromTree(statement.getChild(i + 1)));
            break;
        case DURABLE_WRITES:
            ksDef.setDurable_writes(Boolean.parseBoolean(mValue));
            break;
        default:
            //must match one of the above or we'd throw an exception at the valueOf statement above.
            assert(false);
        }
    }

    // using default snitch options if strategy is NetworkTopologyStrategy and no options were set.
    if (ksDef.getStrategy_class().contains(".NetworkTopologyStrategy"))
    {
        Map<String, String> currentStrategyOptions = ksDef.getStrategy_options();

        // adding default data center from SimpleSnitch
        if (currentStrategyOptions == null || currentStrategyOptions.isEmpty())
        {
            SimpleSnitch snitch = new SimpleSnitch();
            Map<String, String> options = new HashMap<String, String>();
            try
            {
                options.put(snitch.getDatacenter(InetAddress.getLocalHost()), "1");
            }
            catch (UnknownHostException e)
            {
                throw new RuntimeException(e);
            }
            ksDef.setStrategy_options(options);
        }
    }

    return ksDef;
}