|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javatools.parsers.NumberParser
public class NumberParser
This class is part of the Java Tools (see http://mpii.de/yago-naga/javatools). It is licensed under the Creative Commons Attribution License (see http://creativecommons.org/licenses/by/3.0) by the YAGO-NAGA team (see http://mpii.de/yago-naga). The NumberParser normalizes number expressions in English natural language text. It can work with expressions like
10 million meters 7 inches 2.3 sq ft 12:30 pm 100 km 12 ml 10 MbExample:
System.out.println(NumberParser.normalize("It was 1.2 inches long")); --> "It was 0.030479999999999997#meter long" System.out.println(toLong("more than ten kB")); --> 10000.0
Field Summary | |
---|---|
static java.lang.String |
FLOAT
A number as a capturing RegEx |
static java.lang.String |
INT
An integer as a capturing regex |
static java.util.regex.Pattern |
NUMBERPATTERN
The number pattern |
static java.lang.String |
POSINT
An integer as a capturing regex |
static java.util.Map<java.lang.String,java.lang.Double> |
prefixes
Maps decimal prefixes (like "giga") to their double |
Constructor Summary | |
---|---|
NumberParser()
|
Method Summary | |
---|---|
static boolean |
different(java.lang.String n1,
java.lang.String n2)
TRUE if the numbers differ in the unit and or by more than 10% |
static java.lang.Double |
getDouble(java.lang.CharSequence d)
Converts a String that contains a (non-normalized) number to a double or null |
static java.lang.Integer |
getInt(java.lang.CharSequence d)
Converts a String that contains a (non-normalized) number to a int or null |
static java.lang.Long |
getLong(java.lang.CharSequence d)
Converts a String that contains a (non-normalized) number to a long or null |
static java.lang.String |
getNumber(java.lang.CharSequence d)
Extracts the pure number from a String containing a normalized number, else null |
static java.lang.String[] |
getNumberAndUnit(java.lang.CharSequence d,
int[] pos)
Extracts the number and its unit from a String containing a normalized number, else null, returns start and end position in pos[0] and pos[1] resp. |
static java.util.List<java.lang.String> |
getNumbers(java.lang.CharSequence d)
Extracts the numbers and units from a normalized String |
static boolean |
isFloat(java.lang.String s)
Tells whether this string is a normalized number |
static boolean |
isInt(java.lang.String s)
Tells whether this string is a normalized integer number |
static boolean |
isNonNegativeInt(java.lang.String s)
Tells whether this string is a normalized non-negative integer number |
static boolean |
isNumberAndUnit(java.lang.String s)
Tells whether this string is a normalized number with unit |
static void |
main(java.lang.String[] argv)
Test method |
static java.lang.String |
newNumber(double d,
java.lang.String type)
Creates a normalized number from a double and a type. |
static java.lang.String |
newNumber(java.lang.String n)
Creates a normalized number without a type. |
static java.lang.String |
newNumber(java.lang.String n,
java.lang.String type)
Creates a normalized number from a number and a type |
static java.lang.String |
normalize(java.lang.CharSequence s)
Normalizes all numbers in a String Note: If you fix something in this version, please try to apply the same fix at the position change tracking function below |
static java.lang.String |
normalize(java.lang.CharSequence s,
PositionTracker posTracker)
Normalizes all numbers in a String and updates a position mapping with the introduced pos changes Note: If you fix something in this version, please try to apply the same fix at the non-tracking function above |
static java.lang.Double |
parseDouble(java.lang.String d)
Calls Double.parseDouble, returns an Integer or NULL |
static java.lang.Integer |
parseInt(java.lang.String d)
Calls Integer.parseInt, returns an Integer or NULL |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.util.Map<java.lang.String,java.lang.Double> prefixes
public static final java.lang.String FLOAT
public static final java.lang.String POSINT
public static final java.lang.String INT
public static final java.util.regex.Pattern NUMBERPATTERN
Constructor Detail |
---|
public NumberParser()
Method Detail |
---|
public static final java.lang.String newNumber(java.lang.String n, java.lang.String type)
public static final java.lang.String newNumber(java.lang.String n)
newNumber(String n, String type)
public static final java.lang.String newNumber(double d, java.lang.String type)
newNumber(String n, String type)
public static boolean isFloat(java.lang.String s)
public static boolean isInt(java.lang.String s)
public static boolean isNonNegativeInt(java.lang.String s)
public static boolean isNumberAndUnit(java.lang.String s)
public static java.lang.String normalize(java.lang.CharSequence s)
public static java.lang.String normalize(java.lang.CharSequence s, PositionTracker posTracker)
public static java.lang.String getNumber(java.lang.CharSequence d)
public static java.lang.String[] getNumberAndUnit(java.lang.CharSequence d, int[] pos)
public static java.util.List<java.lang.String> getNumbers(java.lang.CharSequence d)
public static java.lang.Double getDouble(java.lang.CharSequence d)
public static java.lang.Long getLong(java.lang.CharSequence d)
public static java.lang.Integer getInt(java.lang.CharSequence d)
public static java.lang.Integer parseInt(java.lang.String d)
public static java.lang.Double parseDouble(java.lang.String d)
public static boolean different(java.lang.String n1, java.lang.String n2)
public static void main(java.lang.String[] argv) throws java.lang.Exception
java.lang.Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |