weka.core.Utils.quote()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(12.5k)|赞(0)|评价(0)|浏览(111)

本文整理了Java中weka.core.Utils.quote()方法的一些代码示例,展示了Utils.quote()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.quote()方法的具体详情如下:
包路径:weka.core.Utils
类名称:Utils
方法名:quote

Utils.quote介绍

[英]Quotes a string if it contains special characters. The following rules are applied: A character is backquoted version of it is one of " ' % \ \n \r \t . A string is enclosed within single quotes if a character has been backquoted using the previous rule above or contains { } or is exactly equal to the strings , ? space or "" (empty string). A quoted question mark distinguishes it from the missing value which is represented as an unquoted question mark in arff files.
[中]如果字符串包含特殊字符,则将其引为引号。应用以下规则:一个字符是反引号,它的版本是“%\n\r\t”中的一个。如果一个字符使用上述规则反引号,或包含{}或与字符串、空格或“”(空字符串)完全相等,则字符串将被括在单引号内.带引号的问号将其与缺失值区分开来,缺失值在arff文件中表示为未带引号的问号。

代码示例

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Get the comma-separated list of labels that are added.
 * 
 * @return the list of labels
 */
public String getLabels() {
 String result;
 int i;
 result = "";
 for (i = 0; i < m_Labels.size(); i++) {
  if (i > 0) {
   result += ",";
  }
  result += Utils.quote(m_Labels.get(i));
 }
 return result;
}

代码示例来源:origin: Waikato/weka-trunk

/**
 * Get the comma-separated list of labels that are added.
 * 
 * @return the list of labels
 */
public String getLabels() {
 String result;
 int i;
 result = "";
 for (i = 0; i < m_Labels.size(); i++) {
  if (i > 0) {
   result += ",";
  }
  result += Utils.quote(m_Labels.get(i));
 }
 return result;
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

m_Out.print("?");
} else {
 m_Out.print(Utils.quote(key[i].toString()));
 m_Out.print("?");
} else {
 m_Out.print(Utils.quote(element.toString()));

代码示例来源:origin: Waikato/weka-trunk

/**
 * returns the matrix in CSV format.
 * 
 * @return        the matrix as string
 */
public String toStringMatrix() {
 StringBuffer        result;
 String[][]          cells;
 int                 i;
 int                 n;
 result = new StringBuffer();
 cells  = toArray();
 for (i = 0; i < cells.length; i++) {
  for (n = 0; n < cells[i].length; n++) {
   if (n > 0)
    result.append(",");
   result.append(Utils.quote(cells[i][n]));
  }
  result.append("\n");
 }
 
 return result.toString();
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * returns the matrix in CSV format.
 * 
 * @return        the matrix as string
 */
public String toStringMatrix() {
 StringBuffer        result;
 String[][]          cells;
 int                 i;
 int                 n;
 result = new StringBuffer();
 cells  = toArray();
 for (i = 0; i < cells.length; i++) {
  for (n = 0; n < cells[i].length; n++) {
   if (n > 0)
    result.append(",");
   result.append(Utils.quote(cells[i][n]));
  }
  result.append("\n");
 }
 
 return result.toString();
}

代码示例来源:origin: Waikato/weka-trunk

m_Out.print("?");
} else {
 m_Out.print(Utils.quote(key[i].toString()));
 m_Out.print("?");
} else {
 m_Out.print(Utils.quote(element.toString()));

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Returns the dataset as a string in ARFF format. Strings are quoted if they
 * contain whitespace characters, or if they are a question mark.
 * 
 * @return the dataset in ARFF format as a string
 */
@Override
public String toString() {
 StringBuffer text = new StringBuffer();
 text.append(ARFF_RELATION).append(" ").append(Utils.quote(m_RelationName))
 .append("\n\n");
 for (int i = 0; i < numAttributes(); i++) {
  text.append(attribute(i)).append("\n");
 }
 text.append("\n").append(ARFF_DATA).append("\n");
 text.append(stringWithoutHeader());
 return text.toString();
}

代码示例来源:origin: Waikato/weka-trunk

/**
 * Returns the dataset as a string in ARFF format. Strings are quoted if they
 * contain whitespace characters, or if they are a question mark.
 * 
 * @return the dataset in ARFF format as a string
 */
@Override
public String toString() {
 StringBuffer text = new StringBuffer();
 text.append(ARFF_RELATION).append(" ").append(Utils.quote(m_RelationName))
 .append("\n\n");
 for (int i = 0; i < numAttributes(); i++) {
  text.append(attribute(i)).append("\n");
 }
 text.append("\n").append(ARFF_DATA).append("\n");
 text.append(stringWithoutHeader());
 return text.toString();
}

代码示例来源:origin: Waikato/weka-trunk

/**
 * Gets the current settings of the datagenerator RDG1. Removing of
 * blacklisted options has to be done in the derived class, that defines the
 * blacklist-entry.
 * 
 * @return an array of strings suitable for passing to setOptions
 * @see #removeBlacklist(String[])
 */
@Override
public String[] getOptions() {
 Vector<String> result = new Vector<String>();
 // to avoid endless loop
 if (!m_CreatingRelationName) {
  result.add("-r");
  result.add(Utils.quote(getRelationNameToUse()));
 }
 if (getDebug()) {
  result.add("-d");
 }
 result.add("-S");
 result.add("" + getSeed());
 return result.toArray(new String[result.size()]);
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Gets the current settings of the datagenerator RDG1. Removing of
 * blacklisted options has to be done in the derived class, that defines the
 * blacklist-entry.
 * 
 * @return an array of strings suitable for passing to setOptions
 * @see #removeBlacklist(String[])
 */
@Override
public String[] getOptions() {
 Vector<String> result = new Vector<String>();
 // to avoid endless loop
 if (!m_CreatingRelationName) {
  result.add("-r");
  result.add(Utils.quote(getRelationNameToUse()));
 }
 if (getDebug()) {
  result.add("-d");
 }
 result.add("-S");
 result.add("" + getSeed());
 return result.toArray(new String[result.size()]);
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * returns a key for all the col names, for better readability if
 * the names got cut off.
 * 
 * @return        the key
 */
public String toStringKey() {
 String          result;
 int             i;
 result = "Key,\n";
 for (i = 0; i < getColCount(); i++) {
  if (getColHidden(i))
   continue;
  result +=   LEFT_PARENTHESES + (i+1) + RIGHT_PARENTHESES
       + "," + Utils.quote(removeFilterName(m_ColNames[i])) + "\n";
 }
 return result;
}

代码示例来源:origin: org.dkpro.tc/dkpro-tc-ml-weka

public static Attribute featureToAttribute(Feature feature) throws TextClassificationException
{
  String name = Utils.quote(feature.getName());
  Object value = feature.getValue();
  Attribute attribute;
  // if value is a number then create a numeric attribute
  if (value instanceof Number) {
    attribute = new Attribute(name);
  } // if value is a boolean then create a numeric attribute
  else if (value instanceof Boolean) {
    attribute = new Attribute(name);
  }
  // if value is an Enum thene create a nominal attribute
  else if (value instanceof Enum) {
    Object[] enumConstants = value.getClass().getEnumConstants();
    ArrayList<String> attributeValues = new ArrayList<String>(enumConstants.length);
    for (Object enumConstant : enumConstants) {
      attributeValues.add(enumConstant.toString());
    }
    attribute = new Attribute(name, attributeValues);
  }
  else {
    attribute = new Attribute(name, (ArrayList<String>) null);
  }
  return attribute;
}

代码示例来源:origin: dkpro/dkpro-tc

public static Attribute featureToAttribute(Feature feature) throws TextClassificationException
{
  String name = Utils.quote(feature.getName());
  Object value = feature.getValue();
  Attribute attribute;
  // if value is a number then create a numeric attribute
  if (value instanceof Number) {
    attribute = new Attribute(name);
  } // if value is a boolean then create a numeric attribute
  else if (value instanceof Boolean) {
    attribute = new Attribute(name);
  }
  // if value is an Enum thene create a nominal attribute
  else if (value instanceof Enum) {
    Object[] enumConstants = value.getClass().getEnumConstants();
    ArrayList<String> attributeValues = new ArrayList<String>(enumConstants.length);
    for (Object enumConstant : enumConstants) {
      attributeValues.add(enumConstant.toString());
    }
    attribute = new Attribute(name, attributeValues);
  }
  else {
    attribute = new Attribute(name, (ArrayList<String>) null);
  }
  return attribute;
}

代码示例来源:origin: ClearTK/cleartk

public static Attribute featureToAttribute(Feature feature, int attributeIndex) {
 String name = Utils.quote(feature.getName());
 Object value = feature.getValue();
 Attribute attribute;
 // if value is a number then create a numeric attribute
 if (value instanceof Number) {
  attribute = new Attribute(name);
 }// if value is a boolean then create a numeric attribute
 else if (value instanceof Boolean) {
  attribute = new Attribute(name);
 }
 // if value is an Enum thene create a nominal attribute
 else if (value instanceof Enum) {
  Object[] enumConstants = value.getClass().getEnumConstants();
  ArrayList<String> attributeValues = new ArrayList<String>(enumConstants.length);
  for (Object enumConstant : enumConstants) {
   attributeValues.add(enumConstant.toString());
  }
  attribute = new Attribute(name, attributeValues);
 }
 // if value is not a number, boolean, or enum, then we will create a
 // string attribute
 else {
  attribute = new Attribute(name, (ArrayList<String>) null);
 }
 return attribute;
}

代码示例来源:origin: de.tudarmstadt.ukp.dkpro.tc/de.tudarmstadt.ukp.dkpro.tc.weka-gpl

public static Attribute featureToAttribute(Feature feature)
  {
    String name = Utils.quote(feature.getName());
    Object value = feature.getValue();
    Attribute attribute;
    // if value is a number then create a numeric attribute
    if (value instanceof Number) {
      attribute = new Attribute(name);
    }// if value is a boolean then create a numeric attribute
    else if (value instanceof Boolean) {
      attribute = new Attribute(name);
    }
    // if value is an Enum thene create a nominal attribute
    else if (value instanceof Enum) {
      Object[] enumConstants = value.getClass().getEnumConstants();
      ArrayList<String> attributeValues = new ArrayList<String>(enumConstants.length);
      for (Object enumConstant : enumConstants) {
        attributeValues.add(enumConstant.toString());
      }
      attribute = new Attribute(name, attributeValues);
    }
    // if value is not a number, boolean, or enum, then we will create a
    // string attribute
    else {
      attribute = new Attribute(name, (ArrayList<String>) null);
    }
    return attribute;
  }
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

|| m_Dataset.attribute(m_Indices[i]).isString()) {
 text.append(m_Indices[i] + " "
  + Utils.quote(m_Dataset.attribute(m_Indices[i]).value(1)));
} else {
 text.append(m_Indices[i] + " 1");

代码示例来源:origin: Waikato/weka-trunk

/**
 * returns a key for all the col names, for better readability if
 * the names got cut off.
 * 
 * @return        the key
 */
public String toStringKey() {
 String          result;
 int             i;
 result = "Key,\n";
 for (i = 0; i < getColCount(); i++) {
  if (getColHidden(i))
   continue;
  result +=   LEFT_PARENTHESES + (i+1) + RIGHT_PARENTHESES
       + "," + Utils.quote(removeFilterName(m_ColNames[i])) + "\n";
 }
 return result;
}

代码示例来源:origin: org.cleartk/cleartk-ml-weka

public static Attribute featureToAttribute(Feature feature, int attributeIndex) {
 String name = Utils.quote(feature.getName());
 Object value = feature.getValue();
 Attribute attribute;
 // if value is a number then create a numeric attribute
 if (value instanceof Number) {
  attribute = new Attribute(name);
 }// if value is a boolean then create a numeric attribute
 else if (value instanceof Boolean) {
  attribute = new Attribute(name);
 }
 // if value is an Enum thene create a nominal attribute
 else if (value instanceof Enum) {
  Object[] enumConstants = value.getClass().getEnumConstants();
  ArrayList<String> attributeValues = new ArrayList<String>(enumConstants.length);
  for (Object enumConstant : enumConstants) {
   attributeValues.add(enumConstant.toString());
  }
  attribute = new Attribute(name, attributeValues);
 }
 // if value is not a number, boolean, or enum, then we will create a
 // string attribute
 else {
  attribute = new Attribute(name, (ArrayList<String>) null);
 }
 return attribute;
}

代码示例来源:origin: org.dkpro.tc/dkpro-tc-ml-weka

throws TextClassificationException
String name = Utils.quote(featureName);
Attribute attribute;

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

output = Utils.quote(input);
assertTrue("No quoting necessary", !output.startsWith("'") && !output.endsWith("'"));
output = Utils.quote(input);
assertTrue("Empty string quoted", output.startsWith("'") && output.endsWith("'"));
assertTrue("Empty string restored", input.equals(Utils.unquote(output)));
output = Utils.quote(input);
assertTrue("Blank quoted", output.startsWith("'") && output.endsWith("'"));
assertTrue("Blank restored", input.equals(Utils.unquote(output)));
output = Utils.quote(input);
assertTrue(">" + input + "< quoted", output.startsWith("'") && output.endsWith("'"));
assertTrue(">" + input + "< restored", input.equals(Utils.unquote(output)));
output = Utils.quote(input);
assertTrue(">" + input + "< quoted", output.startsWith("'") && output.endsWith("'"));
assertTrue(">" + input + "< restored", input.equals(Utils.unquote(output)));
output = Utils.quote(input);
assertTrue(">" + input + "< quoted", output.startsWith("'") && output.endsWith("'"));
assertTrue(">" + input + "< restored", input.equals(Utils.unquote(output)));
output = Utils.quote(input);
assertTrue(">" + input + "< quoted", output.startsWith("'") && output.endsWith("'"));
assertTrue(">" + input + "< restored", input.equals(Utils.unquote(output)));
output = Utils.quote(input);
assertTrue(">" + input + "< quoted", output.startsWith("'") && output.endsWith("'"));

相关文章