Here you can find the source of parseRequestOption(Dictionary
Parameter | Description |
---|---|
conf | The configuration |
confParam | The configuration parameter - '<code>ml.{parameter}</code>' where <code>{parameter}</code> is one of the <a href="http://www.machinelinking.com/wp/documentation/text-annotation/#parameters"> parameters </a> supported by Machinelinking |
requestOptions | the request options map to add the parsed '<code>{parameter}</code>' value |
public static void parseRequestOption(Dictionary<String, Object> conf, String confParam, Map<String, Object> requestOptions)
//package com.java2s; /*/* w w w .j av a 2 s.co m*/ * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.Dictionary; import java.util.Map; public class Main { /** * Parses a request option from the configuration parameters. <p> * <b>IMPORTANT</b>This method assumes that the parsed confParam is * '<code>ml.{parameter}</code> See {@link MLConstants} for defined * constants (e.g. {@link MLConstants#CATEGORY}).<p> * * Supported configuration values are <ul> * <li><code>true/false</code> ({@link Boolean}) * <li><code>0/1</code> ({@link Number}) * <li><code>"0"/"1"</code> and <code>"true"/"false"</code> ({@link String}) * </ul> * * If the requested confParam is not present in the configuration no request * parameter is added to the request options * * @param conf The configuration * @param confParam The configuration parameter - '<code>ml.{parameter}</code>' * where <code>{parameter}</code> is one of the * <a href="http://www.machinelinking.com/wp/documentation/text-annotation/#parameters"> * parameters </a> supported by Machinelinking * @param requestOptions the request options map to add the parsed '<code>{parameter}</code>' value * @see MLConstants * @see <a href="http://www.machinelinking.com/wp/documentation/text-annotation/#parameters"> * Parameters</a> supported by Machinelinking. */ public static void parseRequestOption(Dictionary<String, Object> conf, String confParam, Map<String, Object> requestOptions) { Boolean state = getState(conf, confParam); if (state != null) { String reqParam = confParam.substring(3); //remove the 'ml.{option}' //NOTE: The ML APIClient converts Boolean to the integer 0/1 used // in the RESTful API //requestOptions.put(reqParam, categoryState ? 1 : 0); requestOptions.put(reqParam, state); } // else state not set ... do not add request option } /** * Getter for the state of a boolean type property. Supported configuration values are <ul> * <li><code>true/false</code> ({@link Boolean}) * <li><code>0/1</code> ({@link Number}) * <li><code>"0"/"1"</code> and <code>"true"/"false"</code> ({@link String}) * </ul> * @param conf the configuration * @param property the property * @return the state or <code>null</code> if the property was not present */ public static Boolean getState(Dictionary<String, Object> conf, String property) { Object value = conf.get(property); if (value instanceof String) { String strVal = ((String) value).trim(); if ("0".equals(strVal)) { return false; } else if ("1".equals(strVal)) { return true; } else { return new Boolean(strVal); } } else if (value instanceof Number) { int state = ((Number) value).intValue(); return state == 1 ? Boolean.TRUE : state == 0 ? Boolean.FALSE : null; } else if (value instanceof Boolean) { return (Boolean) value; } else { return null; } } }