Example usage for java.lang Double NEGATIVE_INFINITY

List of usage examples for java.lang Double NEGATIVE_INFINITY

Introduction

In this page you can find the example usage for java.lang Double NEGATIVE_INFINITY.

Prototype

double NEGATIVE_INFINITY

To view the source code for java.lang Double NEGATIVE_INFINITY.

Click Source Link

Document

A constant holding the negative infinity of type double .

Usage

From source file:org.jfree.data.general.DatasetUtils.java

/**
 * Returns the maximum range value for the specified dataset.  This is easy
 * if the dataset implements the {@link RangeInfo} interface (a good idea
 * if there is an efficient way to determine the maximum value).
 * Otherwise, it involves iterating over the entire data-set.  Returns
 * {@code null} if all the data values are {@code null}.
 *
 * @param dataset  the dataset ({@code null} not permitted).
 *
 * @return The maximum value (possibly {@code null}).
 *//*from  w  w w.  j a  v  a  2  s  . c o  m*/
public static Number findMaximumRangeValue(CategoryDataset dataset) {

    Args.nullNotPermitted(dataset, "dataset");

    // work out the minimum value...
    if (dataset instanceof RangeInfo) {
        RangeInfo info = (RangeInfo) dataset;
        return new Double(info.getRangeUpperBound(true));
    }

    // hasn't implemented RangeInfo, so we'll have to iterate...
    else {

        double maximum = Double.NEGATIVE_INFINITY;
        int seriesCount = dataset.getRowCount();
        int itemCount = dataset.getColumnCount();
        for (int series = 0; series < seriesCount; series++) {
            for (int item = 0; item < itemCount; item++) {
                Number value;
                if (dataset instanceof IntervalCategoryDataset) {
                    IntervalCategoryDataset icd = (IntervalCategoryDataset) dataset;
                    value = icd.getEndValue(series, item);
                } else {
                    value = dataset.getValue(series, item);
                }
                if (value != null) {
                    maximum = Math.max(maximum, value.doubleValue());
                }
            }
        }
        if (maximum == Double.NEGATIVE_INFINITY) {
            return null;
        } else {
            return new Double(maximum);
        }

    }

}

From source file:org.jfree.data.general.DatasetUtilities.java

/**
 * Returns the maximum range value for the specified dataset.  This is easy
 * if the dataset implements the {@link RangeInfo} interface (a good idea
 * if there is an efficient way to determine the maximum value).
 * Otherwise, it involves iterating over the entire data-set.  Returns
 * <code>null</code> if all the data values are <code>null</code>.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 *
 * @return The maximum value (possibly <code>null</code>).
 *//*from www  .  j a  va 2  s .  co  m*/
public static Number findMaximumRangeValue(CategoryDataset dataset) {

    ParamChecks.nullNotPermitted(dataset, "dataset");

    // work out the minimum value...
    if (dataset instanceof RangeInfo) {
        RangeInfo info = (RangeInfo) dataset;
        return new Double(info.getRangeUpperBound(true));
    }

    // hasn't implemented RangeInfo, so we'll have to iterate...
    else {

        double maximum = Double.NEGATIVE_INFINITY;
        int seriesCount = dataset.getRowCount();
        int itemCount = dataset.getColumnCount();
        for (int series = 0; series < seriesCount; series++) {
            for (int item = 0; item < itemCount; item++) {
                Number value;
                if (dataset instanceof IntervalCategoryDataset) {
                    IntervalCategoryDataset icd = (IntervalCategoryDataset) dataset;
                    value = icd.getEndValue(series, item);
                } else {
                    value = dataset.getValue(series, item);
                }
                if (value != null) {
                    maximum = Math.max(maximum, value.doubleValue());
                }
            }
        }
        if (maximum == Double.NEGATIVE_INFINITY) {
            return null;
        } else {
            return new Double(maximum);
        }

    }

}

From source file:org.jfree.data.general.DatasetUtils.java

/**
 * Returns the maximum range value for the specified dataset.  This is
 * easy if the dataset implements the {@link RangeInfo} interface (a good
 * idea if there is an efficient way to determine the maximum value).
 * Otherwise, it involves iterating over the entire data-set.  Returns
 * {@code null} if all the data values are {@code null}.
 *
 * @param dataset  the dataset ({@code null} not permitted).
 *
 * @return The maximum value (possibly {@code null}).
 *///w w w  . ja  v  a  2 s  . c om
public static Number findMaximumRangeValue(XYDataset dataset) {

    Args.nullNotPermitted(dataset, "dataset");

    // work out the minimum value...
    if (dataset instanceof RangeInfo) {
        RangeInfo info = (RangeInfo) dataset;
        return new Double(info.getRangeUpperBound(true));
    }

    // hasn't implemented RangeInfo, so we'll have to iterate...
    else {

        double maximum = Double.NEGATIVE_INFINITY;
        int seriesCount = dataset.getSeriesCount();
        for (int series = 0; series < seriesCount; series++) {
            int itemCount = dataset.getItemCount(series);
            for (int item = 0; item < itemCount; item++) {
                double value;
                if (dataset instanceof IntervalXYDataset) {
                    IntervalXYDataset intervalXYData = (IntervalXYDataset) dataset;
                    value = intervalXYData.getEndYValue(series, item);
                } else if (dataset instanceof OHLCDataset) {
                    OHLCDataset highLowData = (OHLCDataset) dataset;
                    value = highLowData.getHighValue(series, item);
                } else {
                    value = dataset.getYValue(series, item);
                }
                if (!Double.isNaN(value)) {
                    maximum = Math.max(maximum, value);
                }
            }
        }
        if (maximum == Double.NEGATIVE_INFINITY) {
            return null;
        } else {
            return new Double(maximum);
        }

    }

}

From source file:whitebox.stats.Kriging.java

/**
 * Creates the pairs list based on sector classification. calcs the distance
 * and moment of inertia for each pair It also calculates the min and max
 * points and boundary It also build the KDTree object to be used with the
 * Kriging//w  w  w . ja v a2s.c  o m
 */
void calPairs4Sec() throws FileNotFoundException {
    MaximumDistance = 0;
    MinX = Double.POSITIVE_INFINITY;
    MinY = Double.POSITIVE_INFINITY;
    MaxX = Double.NEGATIVE_INFINITY;
    MaxY = Double.NEGATIVE_INFINITY;
    pointsTree = new KdTree.SqrEuclid<>(2, new Integer(this.points.size()));
    //PairsTree = new KdTree.SqrEuclid<Double>(2, new Integer(this.Points.size()*(this.Points.size()-1)/2));
    PairsTree = new KdTree.SqrEuclid<>(2, new Integer(this.points.size() * (this.points.size())));
    double[] entry;
    double[] pairentry;

    //        String s = new String();
    double dx = 0;
    double dy = 0;
    for (int i = 0; i < this.points.size(); i++) {

        if (this.points.get(i).x < MinX) {
            MinX = this.points.get(i).x;
        }
        if (this.points.get(i).y < MinY) {
            MinY = this.points.get(i).y;
        }
        if (this.points.get(i).x > MaxX) {
            MaxX = this.points.get(i).x;
        }
        if (this.points.get(i).y > MaxY) {
            MaxY = this.points.get(i).y;
        }

        entry = new double[] { this.points.get(i).y, this.points.get(i).x };
        pointsTree.addPoint(entry, (double) i);

        for (int j = 0; j < this.points.size(); j++) {
            pair pr = new pair();

            if (i != j) {

                pr.FirstP = i;
                pr.SecondP = j;
                pr.Distance = Math.sqrt(Math.pow((points.get(i).x - points.get(j).x), 2)
                        + Math.pow((points.get(i).y - points.get(j).y), 2));

                pr.HorDistance = (points.get(j).x - points.get(i).x);
                pr.VerDistance = (points.get(j).y - points.get(i).y);

                if (MaximumDistance < pr.Distance) {
                    MaximumDistance = pr.Distance;
                }

                dx = points.get(j).x - points.get(i).x;
                dy = points.get(j).y - points.get(i).y;

                if (dx != 0) {
                    if ((dx > 0 && dy >= 0)) {
                        pr.Direction = Math.atan(dy / dx);
                    }
                    if (dx < 0 && dy >= 0) {
                        pr.Direction = Math.atan(dy / dx) + Math.PI;
                    }
                    if (dx > 0 && dy < 0) {
                        pr.Direction = Math.atan(dy / dx) + 2 * Math.PI;
                    }
                    if (dx < 0 && dy < 0) {
                        pr.Direction = Math.atan(dy / dx) + Math.PI;
                        ;
                    }
                } else {
                    if (dy >= 0) {
                        pr.Direction = Math.PI / 2;
                    } else {
                        pr.Direction = 3 * Math.PI / 2;
                    }
                }
                pr.MomentI = Math.pow((points.get(i).z - points.get(j).z), 2) / 2;
                Pairs.add(pr);

                pairentry = new double[] { pr.VerDistance, pr.HorDistance };
                PairsTree.addPoint(pairentry, (double) Pairs.size() - 1.0);

            }
        }
    }

    //        pw.close();
    //LagSize  = MaximumDistance/NumberOfLags;
    bMaxX = MaxX;
    bMaxY = MaxY;
    bMinX = MinX;
    bMinY = MinY;
}

From source file:org.jfree.data.general.DatasetUtilities.java

/**
 * Returns the maximum range value for the specified dataset.  This is
 * easy if the dataset implements the {@link RangeInfo} interface (a good
 * idea if there is an efficient way to determine the maximum value).
 * Otherwise, it involves iterating over the entire data-set.  Returns
 * <code>null</code> if all the data values are <code>null</code>.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 *
 * @return The maximum value (possibly <code>null</code>).
 *//*ww  w .jav  a2s. c  om*/
public static Number findMaximumRangeValue(XYDataset dataset) {

    ParamChecks.nullNotPermitted(dataset, "dataset");

    // work out the minimum value...
    if (dataset instanceof RangeInfo) {
        RangeInfo info = (RangeInfo) dataset;
        return new Double(info.getRangeUpperBound(true));
    }

    // hasn't implemented RangeInfo, so we'll have to iterate...
    else {

        double maximum = Double.NEGATIVE_INFINITY;
        int seriesCount = dataset.getSeriesCount();
        for (int series = 0; series < seriesCount; series++) {
            int itemCount = dataset.getItemCount(series);
            for (int item = 0; item < itemCount; item++) {
                double value;
                if (dataset instanceof IntervalXYDataset) {
                    IntervalXYDataset intervalXYData = (IntervalXYDataset) dataset;
                    value = intervalXYData.getEndYValue(series, item);
                } else if (dataset instanceof OHLCDataset) {
                    OHLCDataset highLowData = (OHLCDataset) dataset;
                    value = highLowData.getHighValue(series, item);
                } else {
                    value = dataset.getYValue(series, item);
                }
                if (!Double.isNaN(value)) {
                    maximum = Math.max(maximum, value);
                }
            }
        }
        if (maximum == Double.NEGATIVE_INFINITY) {
            return null;
        } else {
            return new Double(maximum);
        }

    }

}

From source file:org.jfree.data.general.DatasetUtils.java

/**
 * Returns the minimum and maximum values for the dataset's range
 * (y-values), assuming that the series in one category are stacked.
 *
 * @param dataset  the dataset ({@code null} not permitted).
 * @param base  the base value for the bars.
 *
 * @return The range ({@code null} if the dataset contains no values).
 *///from w  w w  .  j a va  2s .c o  m
public static Range findStackedRangeBounds(CategoryDataset dataset, double base) {
    Args.nullNotPermitted(dataset, "dataset");
    Range result = null;
    double minimum = Double.POSITIVE_INFINITY;
    double maximum = Double.NEGATIVE_INFINITY;
    int categoryCount = dataset.getColumnCount();
    for (int item = 0; item < categoryCount; item++) {
        double positive = base;
        double negative = base;
        int seriesCount = dataset.getRowCount();
        for (int series = 0; series < seriesCount; series++) {
            Number number = dataset.getValue(series, item);
            if (number != null) {
                double value = number.doubleValue();
                if (value > 0.0) {
                    positive = positive + value;
                }
                if (value < 0.0) {
                    negative = negative + value;
                    // '+', remember value is negative
                }
            }
        }
        minimum = Math.min(minimum, negative);
        maximum = Math.max(maximum, positive);
    }
    if (minimum <= maximum) {
        result = new Range(minimum, maximum);
    }
    return result;

}

From source file:org.jfree.data.general.DatasetUtilities.java

/**
 * Returns the minimum and maximum values for the dataset's range
 * (y-values), assuming that the series in one category are stacked.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param base  the base value for the bars.
 *
 * @return The range (<code>null</code> if the dataset contains no values).
 *//*from   ww  w  .  ja v a 2 s.  c  o m*/
public static Range findStackedRangeBounds(CategoryDataset dataset, double base) {
    ParamChecks.nullNotPermitted(dataset, "dataset");
    Range result = null;
    double minimum = Double.POSITIVE_INFINITY;
    double maximum = Double.NEGATIVE_INFINITY;
    int categoryCount = dataset.getColumnCount();
    for (int item = 0; item < categoryCount; item++) {
        double positive = base;
        double negative = base;
        int seriesCount = dataset.getRowCount();
        for (int series = 0; series < seriesCount; series++) {
            Number number = dataset.getValue(series, item);
            if (number != null) {
                double value = number.doubleValue();
                if (value > 0.0) {
                    positive = positive + value;
                }
                if (value < 0.0) {
                    negative = negative + value;
                    // '+', remember value is negative
                }
            }
        }
        minimum = Math.min(minimum, negative);
        maximum = Math.max(maximum, positive);
    }
    if (minimum <= maximum) {
        result = new Range(minimum, maximum);
    }
    return result;

}

From source file:whitebox.stats.Kriging.java

/**
 * Creates the pairs list based for Map classification
 *
 * @throws FileNotFoundException//w  w  w .j  a  v a 2s . c om
 */
void CalPairs4Map() throws FileNotFoundException {
    MaximumDistance = 0;
    MinX = Double.POSITIVE_INFINITY;
    MinY = Double.POSITIVE_INFINITY;
    MaxX = Double.NEGATIVE_INFINITY;
    MaxY = Double.NEGATIVE_INFINITY;
    pointsTree = new KdTree.SqrEuclid<Double>(2, new Integer(this.points.size()));
    PairsTree = new KdTree.SqrEuclid<Double>(2, new Integer(this.points.size() * (this.points.size() - 1) / 2));
    double[] entry;
    double[] pairentry;

    //        String s= new String();
    //        PrintWriter pw ;
    //        pw = new PrintWriter("G:\\test.txt");
    double dx = 0;
    double dy = 0;
    for (int i = 0; i < this.points.size(); i++) {

        if (this.points.get(i).x < MinX) {
            MinX = this.points.get(i).x;
        }
        if (this.points.get(i).y < MinY) {
            MinY = this.points.get(i).y;
        }
        if (this.points.get(i).x > MaxX) {
            MaxX = this.points.get(i).x;
        }
        if (this.points.get(i).y > MaxY) {
            MaxY = this.points.get(i).y;
        }

        entry = new double[] { this.points.get(i).y, this.points.get(i).x };
        pointsTree.addPoint(entry, (double) i);

        for (int j = 0; j < this.points.size(); j++) {
            pair pr = new pair();

            if (points.get(i).x <= points.get(j).x && i != j) {

                pr.FirstP = i;
                pr.SecondP = j;
                pr.Distance = Math.sqrt(Math.pow((points.get(i).x - points.get(j).x), 2)
                        + Math.pow((points.get(i).y - points.get(j).y), 2));

                pr.HorDistance = (points.get(j).x - points.get(i).x);
                pr.VerDistance = (points.get(j).y - points.get(i).y);

                if (MaximumDistance < pr.Distance) {
                    MaximumDistance = pr.Distance;
                }
                dx = points.get(j).x - points.get(i).x;
                dy = points.get(j).y - points.get(i).y;

                if (dx != 0) {
                    if ((dx > 0 && dy >= 0)) {
                        pr.Direction = Math.atan(dy / dx);
                    }
                    if (dx < 0 && dy >= 0) {
                        pr.Direction = Math.atan(dy / dx) + Math.PI;
                    }
                    if (dx > 0 && dy < 0) {
                        pr.Direction = Math.atan(dy / dx) + 2 * Math.PI;
                    }
                    if (dx < 0 && dy < 0) {
                        pr.Direction = Math.atan(dy / dx) + Math.PI;
                        ;
                    }
                } else {
                    if (dy >= 0) {
                        pr.Direction = Math.PI / 2;
                    } else {
                        pr.Direction = 3 * Math.PI / 2;
                    }
                }

                pr.MomentI = Math.pow((points.get(i).z - points.get(j).z), 2) / 2;
                Pairs.add(pr);

                pairentry = new double[] { pr.VerDistance, pr.HorDistance };
                PairsTree.addPoint(pairentry, (double) Pairs.size() - 1.0);

                //                    s =  Double.toString(pr.Distance) + "," + Double.toString(pr.Direction)+
                //                            "," + Double.toString(pr.MomentI)+
                //                            "," + Double.toString(pr.HorDistance)+
                //                            ","+Double.toString(pr.VerDistance)+
                //                            "," + Integer.toString(pr.FirstP)+
                //                            "," + Integer.toString(pr.SecondP);
                //
                //                    pw.println(s);
            }

        }
    }

    //        pw.close();
    //LagSize  = MaximumDistance/NumberOfLags;
    bMaxX = MaxX;
    bMaxY = MaxY;
    bMinX = MinX;
    bMinY = MinY;

}

From source file:imitationNLG.SFX.java

public void createLists(File dataFile) {
    try {//from   w  w  w  .  j ava2 s . c  om
        predicates = new ArrayList<>();
        attributes = new HashMap<>();
        attributeValuePairs = new HashMap<>();
        valueAlignments = new HashMap<>();

        String str = new String();
        boolean begin = false;
        try (BufferedReader br = new BufferedReader(new FileReader(dataFile))) {
            String s;
            while ((s = br.readLine()) != null) {
                if (s.startsWith("[")) {
                    begin = true;
                }
                if (begin) {
                    str += s;
                }
            }
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Bagel.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Bagel.class.getName()).log(Level.SEVERE, null, ex);
        }

        JSONArray overArray = new JSONArray(str);

        for (int o = 0; o < overArray.length(); o++) {
            JSONArray arr = overArray.getJSONObject(o).getJSONArray("dial");
            for (int i = 0; i < arr.length(); i++) {
                String MRstr = "";
                String ref = "";
                MRstr = arr.getJSONObject(i).getJSONObject("S").getString("dact");
                ref = arr.getJSONObject(i).getJSONObject("S").getString("ref").replaceAll("-s", "s");

                if ((MRstr.startsWith("inform(") || MRstr.startsWith("inform_only")
                        || MRstr.startsWith("inform_no_match(") || MRstr.startsWith("?confirm(")
                        || MRstr.startsWith("?select(") || MRstr.startsWith("?request(")
                        || MRstr.startsWith("?reqmore(") || MRstr.startsWith("goodbye(")) && !ref.isEmpty()) {
                    String predicate = MRstr.substring(0, MRstr.indexOf("("));
                    if (!predicates.contains(predicate) && predicate != null) {
                        predicates.add(predicate);

                        if (!attributes.containsKey(predicate)) {
                            attributes.put(predicate, new HashSet<String>());
                        }
                        if (!datasetInstances.containsKey(predicate)) {
                            datasetInstances.put(predicate, new ArrayList<DatasetInstance>());
                        }
                    }

                    String attributesStr = MRstr.substring(MRstr.indexOf('(') + 1, MRstr.length() - 1);
                    HashMap<String, HashSet<String>> attributeValues = new HashMap<>();
                    if (!attributesStr.isEmpty()) {
                        HashMap<String, Integer> attrXIndeces = new HashMap<>();

                        String[] args = attributesStr.split(";");
                        if (attributesStr.contains("|")) {
                            System.out.println(attributesStr);
                            System.exit(0);
                        }
                        for (String arg : args) {
                            String attr = "";
                            String value = "";
                            if (arg.contains("=")) {
                                String[] subAttr = arg.split("=");
                                value = subAttr[1].toLowerCase();
                                attr = subAttr[0].toLowerCase().replaceAll("_", "");
                            } else {
                                attr = arg.replaceAll("_", "");
                            }
                            if (!attributes.get(predicate).contains(attr)) {
                                attributes.get(predicate).add(attr);
                            }
                            if (!attributeValues.containsKey(attr)) {
                                attributeValues.put(attr, new HashSet<String>());
                            }
                            if (value.isEmpty()) {
                                value = attr;
                            }

                            if (value.startsWith("\'")) {
                                value = value.substring(1, value.length() - 1);
                            }
                            if (value.toLowerCase().startsWith("x")) {
                                int index = 0;
                                if (!attrXIndeces.containsKey(attr)) {
                                    attrXIndeces.put(attr, 1);
                                } else {
                                    index = attrXIndeces.get(attr);
                                    attrXIndeces.put(attr, index + 1);
                                }
                                value = "x" + index;
                            }
                            if (value.isEmpty()) {
                                System.out.println("EMPTY VALUE");
                                System.exit(0);
                            }

                            attributeValues.get(attr).add(value.trim().toLowerCase());
                        }
                        for (String attr : attributeValues.keySet()) {
                            if (attributeValues.get(attr).contains("yes")
                                    && attributeValues.get(attr).contains("no")) {
                                System.out.println(MRstr);
                                System.out.println(attributeValues);
                                System.exit(0);
                            }
                        }
                    }

                    //REF
                    //DELEXICALIZATION
                    HashMap<String, HashMap<String, Integer>> attrValuePriorities = new HashMap<>();
                    HashMap<String, HashSet<String>> delexAttributeValues = new HashMap<>();
                    int prio = 0;
                    for (String attr : attributeValues.keySet()) {
                        if (!attr.isEmpty()) {
                            delexAttributeValues.put(attr, new HashSet<String>());
                            if (attr.equals("name") || attr.equals("type") || attr.equals("pricerange")
                                    || attr.equals("price") || attr.equals("phone") || attr.equals("address")
                                    || attr.equals("postcode") || attr.equals("area") || attr.equals("near")
                                    || attr.equals("food") || attr.equals("count")
                                    || attr.equals("goodformeal")) {
                                attrValuePriorities.put(attr, new HashMap<String, Integer>());
                                for (String value : attributeValues.get(attr)) {
                                    if (!value.equals("dont_care") && !value.equals("none")
                                            && !value.equals("empty") && !value.equals(attr)) {
                                        attrValuePriorities.get(attr).put(value, prio);
                                        prio++;
                                    } else {
                                        delexAttributeValues.get(attr).add(value);
                                    }
                                }
                            } else {
                                for (String value : attributeValues.get(attr)) {
                                    delexAttributeValues.get(attr).add(value);
                                }
                            }
                        }
                    }
                    boolean change = true;
                    while (change) {
                        change = false;
                        for (String attr1 : attrValuePriorities.keySet()) {
                            for (String value1 : attrValuePriorities.get(attr1).keySet()) {
                                for (String attr2 : attrValuePriorities.keySet()) {
                                    for (String value2 : attrValuePriorities.get(attr2).keySet()) {
                                        if (!value1.equals(value2) && value1.contains(value2)
                                                && attrValuePriorities.get(attr1).get(
                                                        value1) > attrValuePriorities.get(attr2).get(value2)) {
                                            int prio1 = attrValuePriorities.get(attr1).get(value1);
                                            int prio2 = attrValuePriorities.get(attr2).get(value2);
                                            attrValuePriorities.get(attr1).put(value1, prio2);
                                            attrValuePriorities.get(attr2).put(value2, prio1);
                                            change = true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    HashMap<String, Integer> xCounts = new HashMap<>();
                    HashMap<String, String> delexMap = new HashMap<>();
                    ref = " " + ref + " ";
                    for (int p = 0; p < prio; p++) {
                        for (String attr : attrValuePriorities.keySet()) {
                            if (!xCounts.containsKey(attr)) {
                                xCounts.put(attr, 0);
                            }
                            for (String value : attrValuePriorities.get(attr).keySet()) {
                                if (attrValuePriorities.get(attr).get(value) == p) {
                                    if (!ref.contains(" " + value + " ") && !value.contains(" and ")
                                            && !value.contains(" or ")) {
                                        /*System.out.println(ref);
                                         System.out.println(attr);
                                         System.out.println(value);
                                         System.out.println(attrValuePriorities);*/
                                    } else if (!ref.contains(" " + value + " ")
                                            && (value.contains(" and ") || value.contains(" or "))) {
                                        String[] values = null;
                                        if (value.contains(" and ")) {
                                            values = value.split(" and ");
                                        } else if (value.contains(" or ")) {
                                            values = value.split(" or ");
                                        }
                                        for (int v = 0; v < values.length; v++) {
                                            if (!ref.contains(" " + values[v] + " ")) {
                                                /*System.out.println(ref);
                                                 System.out.println(attr);
                                                 System.out.println(value);
                                                 System.out.println(values[v]);
                                                 System.out.println(attrValuePriorities);*/
                                            } else {
                                                ref = ref.replace(" " + values[v] + " ", " " + SFX.TOKEN_X
                                                        + attr + "_" + xCounts.get(attr) + " ");
                                                ref = ref.replaceAll("  ", " ");
                                                delexAttributeValues.get(attr)
                                                        .add(SFX.TOKEN_X + attr + "_" + xCounts.get(attr));
                                                delexMap.put(SFX.TOKEN_X + attr + "_" + xCounts.get(attr),
                                                        values[v]);
                                                xCounts.put(attr, xCounts.get(attr) + 1);
                                            }
                                        }
                                    } else {
                                        ref = ref.replace(" " + value + " ",
                                                " " + SFX.TOKEN_X + attr + "_" + xCounts.get(attr) + " ");
                                        ref = ref.replaceAll("  ", " ");
                                        delexAttributeValues.get(attr)
                                                .add(SFX.TOKEN_X + attr + "_" + xCounts.get(attr));
                                        delexMap.put(SFX.TOKEN_X + attr + "_" + xCounts.get(attr), value);
                                        xCounts.put(attr, xCounts.get(attr) + 1);
                                    }
                                }
                            }
                        }
                    }
                    ref = ref.trim();
                    MeaningRepresentation MR = new MeaningRepresentation(predicate, delexAttributeValues,
                            MRstr);
                    MR.setDelexMap(delexMap);

                    ArrayList<String> mentionedValueSequence = new ArrayList<>();
                    ArrayList<String> mentionedAttributeSequence = new ArrayList<>();

                    ArrayList<String> realization = new ArrayList<>();
                    ArrayList<String> alignedRealization = new ArrayList<>();

                    String[] words = ref.replaceAll("([,.?!;:'])", " $1").split(" ");
                    HashMap<String, Integer> attributeXCount = new HashMap<>();
                    for (int w = 0; w < words.length; w++) {
                        String mentionedAttribute = "";
                        if (!words[w].trim().isEmpty()) {
                            int s = words[w].indexOf("[");
                            if (s != -1) {
                                int e = words[w].indexOf("]", s + 1);

                                String mentionedValue = words[w].substring(s, e + 1);
                                words[w] = words[w].replace(mentionedValue, "");
                                if (mentionedValue.contains("+") && !words[w].trim().isEmpty()) {
                                    mentionedAttribute = mentionedValue.substring(1,
                                            mentionedValue.indexOf("+"));

                                    if (MR.getAttributes().containsKey(mentionedAttribute)) {
                                        if (mentionedValueSequence.isEmpty()) {
                                            String v = mentionedValue.substring(1, mentionedValue.length() - 1)
                                                    .replaceAll("\\+", "=");
                                            if (v.endsWith("=X")) {
                                                //v = v.replace("=X", "=@@$$" + a + "$$@@");
                                                int a = 0;
                                                if (!attributeXCount.containsKey(mentionedAttribute)) {
                                                    attributeXCount.put(mentionedAttribute, 1);
                                                } else {
                                                    a = attributeXCount.get(mentionedAttribute);
                                                    attributeXCount.put(mentionedAttribute,
                                                            attributeXCount.get(mentionedAttribute) + 1);
                                                }
                                                v = v.replace("=X", "=x" + a);
                                            }
                                            mentionedValueSequence.add(v.toLowerCase());
                                        } else if (!mentionedValueSequence
                                                .get(mentionedValueSequence.size() - 1)
                                                .equals(mentionedValue)) {
                                            String v = mentionedValue.substring(1, mentionedValue.length() - 1)
                                                    .replaceAll("\\+", "=");
                                            if (v.endsWith("=X")) {
                                                //v = v.replace("=X", "=@@$$" + +a + "$$@@");
                                                int a = 0;
                                                if (!attributeXCount.containsKey(mentionedAttribute)) {
                                                    attributeXCount.put(mentionedAttribute, 1);
                                                } else {
                                                    a = attributeXCount.get(mentionedAttribute);
                                                    attributeXCount.put(mentionedAttribute,
                                                            attributeXCount.get(mentionedAttribute) + 1);
                                                }
                                                v = v.replace("=X", "=x" + a);
                                            }
                                            mentionedValueSequence.add(v.toLowerCase());
                                        }

                                        if (mentionedAttributeSequence.isEmpty()) {
                                            mentionedAttributeSequence.add(mentionedAttribute.toLowerCase());
                                        } else if (!mentionedAttributeSequence
                                                .get(mentionedAttributeSequence.size() - 1)
                                                .equals(mentionedAttribute)) {
                                            mentionedAttributeSequence.add(mentionedAttribute.toLowerCase());
                                        }
                                    }
                                } else if (!words[w].trim().isEmpty()) {
                                    mentionedAttribute = mentionedValue.substring(1,
                                            mentionedValue.length() - 1);

                                    if (!MR.getAttributes().containsKey(mentionedAttribute)) {
                                        mentionedAttribute = "";
                                    }
                                }
                            }
                            if (!words[w].trim().isEmpty()) {
                                if (words[w].trim().equals("thers")) {
                                    realization.add("there");
                                } else {
                                    realization.add(words[w].trim().toLowerCase());
                                }
                            }
                        }
                    }

                    for (String attr : MR.getAttributes().keySet()) {
                        for (String value : MR.getAttributes().get(attr)) {
                            if (attr.equals("name") && value.equals("none")) {
                                mentionedValueSequence.add(0, attr.toLowerCase() + "=" + value.toLowerCase());
                                mentionedAttributeSequence.add(0, attr.toLowerCase());
                            }
                        }
                    }

                    mentionedValueSequence.add(SFX.TOKEN_END);
                    mentionedAttributeSequence.add(SFX.TOKEN_END);
                    if (realization.size() > maxWordRealizationSize) {
                        maxWordRealizationSize = realization.size();
                    }

                    for (String word : realization) {
                        if (word.trim().matches("[,.?!;:']")) {
                            alignedRealization.add(SFX.TOKEN_PUNCT);
                        } else {
                            alignedRealization.add("[]");
                        }
                    }

                    //Calculate alignments
                    HashMap<String, HashMap<String, Double>> alignments = new HashMap<>();
                    for (String attr : MR.getAttributes().keySet()) {
                        /*if (attr.equals("name")
                         || attr.equals("type")
                         || attr.equals("pricerange")
                         || attr.equals("price")
                         || attr.equals("phone")
                         || attr.equals("address")
                         || attr.equals("postcode")
                         || attr.equals("area")
                         || attr.equals("near")
                         || attr.equals("food")
                         || attr.equals("count")
                         || attr.equals("goodformeal")) {*/

                        for (String value : MR.getAttributes().get(attr)) {
                            if (!value.equals("name=none") && !value.startsWith(SFX.TOKEN_X)
                                    && !(value.matches("\"[xX][0-9]+\"") || value.matches("[xX][0-9]+"))) {
                                String valueToCheck = value;
                                if (value.equals("no") || value.equals("yes") || value.equals("yes or no")
                                        || value.equals("none") || value.equals("dont_care")
                                        || value.equals("empty")) {
                                    valueToCheck = attr;
                                    alignments.put(valueToCheck + ":" + value, new HashMap<String, Double>());
                                } else {
                                    alignments.put(valueToCheck, new HashMap<String, Double>());
                                }
                                //For all ngrams
                                for (int n = 1; n < realization.size(); n++) {
                                    //Calculate all alignment similarities
                                    for (int r = 0; r <= realization.size() - n; r++) {
                                        boolean pass = true;
                                        for (int j = 0; j < n; j++) {
                                            if (realization.get(r + j).startsWith(SFX.TOKEN_X)
                                                    || alignedRealization.get(r + j).equals(SFX.TOKEN_PUNCT)
                                                    || StringNLPUtilities.isArticle(realization.get(r + j))
                                                    || realization.get(r + j).equalsIgnoreCase("and")
                                                    || realization.get(r + j).equalsIgnoreCase("or")) {
                                                pass = false;
                                            }
                                        }
                                        if (pass) {
                                            String align = "";
                                            String compare = "";
                                            String backwardCompare = "";
                                            for (int j = 0; j < n; j++) {
                                                align += (r + j) + " ";
                                                compare += realization.get(r + j);
                                                backwardCompare = realization.get(r + j) + backwardCompare;
                                            }
                                            align = align.trim();

                                            Double distance = Levenshtein.getSimilarity(
                                                    valueToCheck.toLowerCase(), compare.toLowerCase(), true,
                                                    false);
                                            Double backwardDistance = Levenshtein.getSimilarity(
                                                    valueToCheck.toLowerCase(), backwardCompare.toLowerCase(),
                                                    true, false);

                                            if (backwardDistance > distance) {
                                                distance = backwardDistance;
                                            }
                                            if (distance > 0.3) {
                                                if (value.equals("no") || value.equals("yes")
                                                        || value.equals("yes or no") || value.equals("none")
                                                        || value.equals("dont_care") || value.equals("empty")) {
                                                    alignments.get(valueToCheck + ":" + value).put(align,
                                                            distance);
                                                } else {
                                                    alignments.get(valueToCheck).put(align, distance);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        /*} else {
                         for (String value : MR.getAttributes().get(attr)) {
                         if (!value.equals("no")
                         && !value.equals("yes")
                         && !value.equals("none")) {
                         System.out.println(attr + " " + value);
                         }
                         }
                         }*/
                    }

                    HashSet<String> toRemove = new HashSet<>();
                    for (String value : alignments.keySet()) {
                        if (alignments.get(value).isEmpty()) {
                            toRemove.add(value);
                        }
                    }
                    for (String value : toRemove) {
                        alignments.remove(value);
                    }

                    while (!alignments.keySet().isEmpty()) {
                        Double max = Double.NEGATIVE_INFINITY;
                        String[] bestAlignment = new String[2];
                        for (String value : alignments.keySet()) {
                            for (String alignment : alignments.get(value).keySet()) {
                                if (alignments.get(value).get(alignment) > max) {
                                    max = alignments.get(value).get(alignment);
                                    bestAlignment[0] = value;
                                    bestAlignment[1] = alignment;
                                }
                            }
                        }

                        ArrayList<String> alignedStr = new ArrayList<>();
                        String[] coords = bestAlignment[1].split(" ");

                        if (coords.length == 1) {
                            alignedStr.add(realization.get(Integer.parseInt(coords[0].trim())));
                        } else {
                            for (int a = Integer.parseInt(coords[0].trim()); a <= Integer
                                    .parseInt(coords[coords.length - 1].trim()); a++) {
                                alignedStr.add(realization.get(a));
                            }
                        }

                        if (!valueAlignments.containsKey(bestAlignment[0])) {
                            valueAlignments.put(bestAlignment[0], new HashMap<ArrayList<String>, Double>());
                        }
                        valueAlignments.get(bestAlignment[0]).put(alignedStr, max);

                        alignments.remove(bestAlignment[0]);
                        for (String value : alignments.keySet()) {
                            HashSet<String> alignmentsToBeRemoved = new HashSet<>();
                            for (String alignment : alignments.get(value).keySet()) {
                                String[] othCoords = alignment.split(" ");
                                if (Integer.parseInt(coords[0].trim()) <= Integer.parseInt(othCoords[0].trim())
                                        && (Integer.parseInt(coords[coords.length - 1].trim()) >= Integer
                                                .parseInt(othCoords[0].trim()))
                                        || (Integer.parseInt(othCoords[0].trim()) <= Integer
                                                .parseInt(coords[0].trim())
                                                && Integer.parseInt(
                                                        othCoords[othCoords.length - 1].trim()) >= Integer
                                                                .parseInt(coords[0].trim()))) {
                                    alignmentsToBeRemoved.add(alignment);
                                }
                            }
                            for (String alignment : alignmentsToBeRemoved) {
                                alignments.get(value).remove(alignment);
                            }
                        }
                        toRemove = new HashSet<>();
                        for (String value : alignments.keySet()) {
                            if (alignments.get(value).isEmpty()) {
                                toRemove.add(value);
                            }
                        }
                        for (String value : toRemove) {
                            alignments.remove(value);
                        }
                    }
                    String previousAttr = "";
                    for (int a = alignedRealization.size() - 1; a >= 0; a--) {
                        if (alignedRealization.get(a).isEmpty() || alignedRealization.get(a).equals("[]")) {
                            if (!previousAttr.isEmpty()) {
                                alignedRealization.set(a, previousAttr);
                            }
                        } else if (!alignedRealization.get(a).equals(SFX.TOKEN_PUNCT)) {
                            previousAttr = alignedRealization.get(a);
                        } else {
                            previousAttr = "";
                        }
                    }
                    previousAttr = "";
                    for (int a = 0; a < alignedRealization.size(); a++) {
                        if (alignedRealization.get(a).isEmpty() || alignedRealization.get(a).equals("[]")) {
                            if (!previousAttr.isEmpty()) {
                                alignedRealization.set(a, previousAttr);
                            }
                        } else if (!alignedRealization.get(a).equals(SFX.TOKEN_PUNCT)) {
                            previousAttr = alignedRealization.get(a);
                        } else {
                            previousAttr = "";
                        }
                    }

                    //}
                    ArrayList<Action> realizationActions = new ArrayList<>();
                    for (int r = 0; r < realization.size(); r++) {
                        realizationActions.add(new Action(realization.get(r), alignedRealization.get(r)));
                    }

                    //boolean existing = false;
                    DatasetInstance DI = new DatasetInstance(MR, mentionedValueSequence,
                            mentionedAttributeSequence, realizationActions);
                    for (DatasetInstance existingDI : datasetInstances.get(predicate)) {
                        //if (existingDI.getMeaningRepresentation().equals(previousAMR)) {
                        //if (existingDI.getMeaningRepresentation().getAttributes().equals(MR.getAttributes())) {
                        if (existingDI.getMeaningRepresentation().getAttributes()
                                .equals(DI.getMeaningRepresentation().getAttributes())) {
                            //existing = true;
                            //existingDI.mergeDatasetInstance(mentionedValueSequence, mentionedAttributeSequence, realizationActions);
                            existingDI.mergeDatasetInstance(DI.getEvalMentionedValueSequences(),
                                    DI.getEvalMentionedAttributeSequences(), DI.getEvalRealizations());
                            DI.mergeDatasetInstance(existingDI.getEvalMentionedValueSequences(),
                                    existingDI.getEvalMentionedAttributeSequences(),
                                    existingDI.getEvalRealizations());
                        }
                    }
                    //if (!existing) {
                    //DatasetInstance DI = new DatasetInstance(MR, mentionedValueSequence, mentionedAttributeSequence, realizationActions);
                    datasetInstances.get(predicate).add(DI);
                    //}
                }
                //}
            }
        }
        /*int dis = 0;
         int slots = 0;
         for (String pred : datasetInstances.keySet()) {
         System.out.println("FOR PREDICATE: " + pred);
         System.out.println("=====");
         for (DatasetInstance di : datasetInstances.get(pred)) {
         System.out.println(di.getMeaningRepresentation().getPredicate());
         System.out.println(di.getMeaningRepresentation().getAttributes());
                
         System.out.println("***********");
         System.out.println("R: " + di.getEvalRealizations());
         System.out.println("=======================");
         dis++;
         slots += di.getMeaningRepresentation().getAttributes().size();
         }
         }
         System.out.println(dis);
         System.out.println((double) slots / (double) dis);*/
    } catch (JSONException ex) {
        ex.printStackTrace();
    }
}

From source file:gov.anl.cue.arcane.engine.matrix.MatrixModel.java

/**
 * Gets the fitness value./*from   w ww .  ja  va 2s  . c om*/
 *
 * @return the fitness value
 */
public Double getFitnessValue() {

    // Check the current value, if any.
    if (this.fitnessValue == null) {

        // Calculate this model's fitness value.
        this.fitnessValue = this.calculateFitnessValue();

        // Override invalid values.
        if (Double.isNaN(this.fitnessValue)) {
            this.fitnessValue = Double.NEGATIVE_INFINITY;
        }

    }

    // Return the previously calculate result.
    return this.fitnessValue;

}