Example usage for java.util List contains

List of usage examples for java.util List contains

Introduction

In this page you can find the example usage for java.util List contains.

Prototype

boolean contains(Object o);

Source Link

Document

Returns true if this list contains the specified element.

Usage

From source file:de.tudarmstadt.ukp.similarity.experiments.coling2012.util.WordIdfValuesGenerator.java

@SuppressWarnings("unchecked")
public static void computeIdfScores(Dataset dataset) throws Exception {
    File outputFile = new File(UTILS_DIR + "/word-idf/" + dataset.toString() + ".txt");

    System.out.println("Computing word idf values");

    if (outputFile.exists()) {
        System.out.println(" - skipping, already exists");
    } else {/*from   w ww .ja v a 2  s .  c  o  m*/
        System.out.println(" - this may take a while...");

        CollectionReader reader = ColingUtils.getCollectionReader(dataset);

        // Tokenization
        AnalysisEngineDescription seg = createPrimitiveDescription(BreakIteratorSegmenter.class);
        AggregateBuilder builder = new AggregateBuilder();
        builder.add(seg, CombinationReader.INITIAL_VIEW, CombinationReader.VIEW_1);
        builder.add(seg, CombinationReader.INITIAL_VIEW, CombinationReader.VIEW_2);
        AnalysisEngine aggr_seg = builder.createAggregate();

        // POS Tagging
        AnalysisEngineDescription pos = createPrimitiveDescription(OpenNlpPosTagger.class,
                OpenNlpPosTagger.PARAM_LANGUAGE, "en");
        builder = new AggregateBuilder();
        builder.add(pos, CombinationReader.INITIAL_VIEW, CombinationReader.VIEW_1);
        builder.add(pos, CombinationReader.INITIAL_VIEW, CombinationReader.VIEW_2);
        AnalysisEngine aggr_pos = builder.createAggregate();

        // Lemmatization
        AnalysisEngineDescription lem = createPrimitiveDescription(StanfordLemmatizer.class);
        builder = new AggregateBuilder();
        builder.add(lem, CombinationReader.INITIAL_VIEW, CombinationReader.VIEW_1);
        builder.add(lem, CombinationReader.INITIAL_VIEW, CombinationReader.VIEW_2);
        AnalysisEngine aggr_lem = builder.createAggregate();

        // Output Writer
        AnalysisEngine writer = createPrimitive(WordIdfValuesGeneratorWriter.class,
                WordIdfValuesGeneratorWriter.PARAM_OUTPUT_FILE, outputFile.getAbsolutePath());

        SimplePipeline.runPipeline(reader, aggr_seg, aggr_pos, aggr_lem, writer);

        // Now we have the text format lemma1###lemma2###...###lemman
        List<String> lines = FileUtils.readLines(outputFile);

        Map<String, Double> idfValues = new HashMap<String, Double>();

        // Build up token representations of texts
        Set<List<String>> docs = new HashSet<List<String>>();

        for (String line : lines) {
            List<String> doc = CollectionUtils.arrayToList(line.split("###"));

            docs.add(doc);
        }

        // Get the shared token list
        Set<String> tokens = new HashSet<String>();
        for (List<String> doc : docs)
            tokens.addAll(doc);

        // Get the idf numbers
        for (String token : tokens) {
            double count = 0;
            for (List<String> doc : docs) {
                if (doc.contains(token))
                    count++;
            }
            idfValues.put(token, count);
        }

        // Compute the idf
        for (String lemma : idfValues.keySet()) {
            double idf = Math.log10(lines.size() / idfValues.get(lemma));
            idfValues.put(lemma, idf);
        }

        // Store persistently
        StringBuilder sb = new StringBuilder();
        for (String key : idfValues.keySet()) {
            sb.append(key + "\t" + idfValues.get(key) + LF);
        }
        FileUtils.writeStringToFile(outputFile, sb.toString());

        System.out.println(" - done");
    }
}

From source file:jease.site.Fulltexts.java

/**
 * Returns all visible content which descends from given context and matches
 * the given query./*from   w  w w  . jav a  2s .  c  om*/
 */
public static List<Content> query(Content context, String query) {
    try {
        List<Content> result = new ArrayList<>();
        for (Content content : Database.query(fullTextIndex).search(query)) {
            // When content is child of a "paged container" (e.g.
            // Composite), traverse upwards to the top-level container.
            Content target = content;
            while (target.getParent() != null && ((Content) target.getParent()).isPage()
                    && target.getParent().isContainer()) {
                target = (Content) target.getParent();
            }
            if (!result.contains(target) && (context == null || target.isDescendant(context))) {
                result.add(target);
            }
        }
        return result;
    } catch (Exception e) {
        return Collections.EMPTY_LIST;
    }
}

From source file:com.doculibre.constellio.services.FederationServicesImpl.java

private static void addOwnerCollections(RecordCollection includedCollection,
        List<RecordCollection> allOwnerCollections) {
    for (RecordCollection ownerCollection : includedCollection.getOwnerCollections()) {
        if (!allOwnerCollections.contains(ownerCollection)) {
            allOwnerCollections.add(ownerCollection);
            // Recursive call
            addOwnerCollections(ownerCollection, allOwnerCollections);
        }//from w w w .  j a  va 2 s  .  c om
    }
}

From source file:LocaleUtils.java

/**
 * <p>Obtains the list of locales to search through when performing
 * a locale search.</p>/*from  ww w  . j  av  a  2 s  .  c  o  m*/
 *
 * <pre>
 * localeLookupList(Locale("fr", "CA", "xxx"), Locale("en"))
 *   = [Locale("fr","CA","xxx"), Locale("fr","CA"), Locale("fr"), Locale("en"]
 * </pre>
 *
 * <p>The result list begins with the most specific locale, then the
 * next more general and so on, finishing with the default locale.
 * The list will never contain the same locale twice.</p>
 *
 * @param locale  the locale to start from, null returns empty list
 * @param defaultLocale  the default locale to use if no other is found
 * @return the unmodifiable list of Locale objects, 0 being locale, never null
 */
public static List localeLookupList(Locale locale, Locale defaultLocale) {
    List list = new ArrayList(4);
    if (locale != null) {
        list.add(locale);
        if (locale.getVariant().length() > 0) {
            list.add(new Locale(locale.getLanguage(), locale.getCountry()));
        }
        if (locale.getCountry().length() > 0) {
            list.add(new Locale(locale.getLanguage(), ""));
        }
        if (list.contains(defaultLocale) == false) {
            list.add(defaultLocale);
        }
    }
    return Collections.unmodifiableList(list);
}

From source file:org.fastj.fit.tool.JSONHelper.java

private static List<String> uniqueChildName(Element e) {
    List<String> l = new ArrayList<String>();
    for (Object o : e.getChildren()) {
        if (o instanceof Element) {
            Element se = (Element) o;
            if (!l.contains(se.getName())) {
                l.add(se.getName());//  w  ww  . j a  v a 2s. co  m
            }
        }
    }
    return l;
}

From source file:it.eng.spagobi.engines.worksheet.bo.WorkSheetDefinition.java

public static Map<String, List<String>> mergeDomainValuesFilters(List<Attribute> globalFilters,
        List<Attribute> sheetFilters) throws WrongConfigurationForFiltersOnDomainValuesException {
    Iterator<Attribute> globalFiltersIt = globalFilters.iterator();
    Map<String, List<String>> toReturn = new HashMap<String, List<String>>();
    while (globalFiltersIt.hasNext()) {
        Attribute aGlobalFilter = globalFiltersIt.next();
        if (sheetFilters.contains(aGlobalFilter)) { // the filter is defined globally and also on sheets
            // wins the more restrictive filter
            int index = sheetFilters.indexOf(aGlobalFilter);
            Attribute sheetsFilter = sheetFilters.get(index);
            List<String> aGlobalFilterValues = aGlobalFilter.getValuesAsList();
            List<String> sheetsFilterValues = sheetsFilter.getValuesAsList();
            if (aGlobalFilterValues.containsAll(sheetsFilterValues)) {
                // the sheets filters are less or equal to the global filters (this should always happen)
                toReturn.put(aGlobalFilter.getEntityId(), sheetsFilterValues);
            } else {
                logger.error("The global filter on field " + aGlobalFilter.getAlias()
                        + " is overridden by the sheet.");
                throw new WrongConfigurationForFiltersOnDomainValuesException(
                        "The global filter on field " + aGlobalFilter.getAlias()
                                + " is overridden by the sheet. Please expand the global filter's values.");
            }/*from ww  w .j av  a 2 s  . c  om*/
        } else {
            toReturn.put(aGlobalFilter.getEntityId(), aGlobalFilter.getValuesAsList());
        }
    }
    Iterator<Attribute> sheetFiltersIt = sheetFilters.iterator();
    while (sheetFiltersIt.hasNext()) {
        Attribute aSheetsFilter = sheetFiltersIt.next();
        if (toReturn.containsKey(aSheetsFilter.getEntityId())) {
            // conflict already solved
            continue;
        }
        toReturn.put(aSheetsFilter.getEntityId(), aSheetsFilter.getValuesAsList());
    }
    return toReturn;
}

From source file:org.jfree.chart.demo.SampleYSymbolicDataset.java

/**
 * This function modify <CODE>dataset1</CODE> and <CODE>dataset1</CODE> in
 * order that they share the same symbolic value list.
 * <P>/*from  w ww . ja  va 2 s.c o m*/
 * The sharing symbolic value list is obtained adding the symbolic data list of the fist data set to the symbolic data list of the second data set.
 * <P>
 * This function is use with the <I>combined plot</I> functions of JFreeChart.
 * 
 * @param dataset1
 *           the first data set to combine.
 * @param dataset2
 *           the second data set to combine.
 * @return the shared symbolic array.
 */
public static String[] combineYSymbolicDataset(final YisSymbolic dataset1, final YisSymbolic dataset2) {

    final SampleYSymbolicDataset sDataset1 = (SampleYSymbolicDataset) dataset1;
    final SampleYSymbolicDataset sDataset2 = (SampleYSymbolicDataset) dataset2;
    final String[] sDatasetSymbolicValues1 = sDataset1.getYSymbolicValues();
    final String[] sDatasetSymbolicValues2 = sDataset2.getYSymbolicValues();

    // Combine the two list of symbolic value of the two data set
    final int s1length = sDatasetSymbolicValues1.length;
    final int s2length = sDatasetSymbolicValues2.length;
    final List ySymbolicValuesCombined = new Vector();
    for (int i = 0; i < s1length; i++) {
        ySymbolicValuesCombined.add(sDatasetSymbolicValues1[i]);
    }
    for (int i = 0; i < s2length; i++) {
        if (!ySymbolicValuesCombined.contains(sDatasetSymbolicValues2[i])) {
            ySymbolicValuesCombined.add(sDatasetSymbolicValues2[i]);
        }
    }

    // Change the Integer reference of the second data set
    int newIndex;
    for (int i = 0; i < sDataset2.getSeriesCount(); i++) {
        for (int j = 0; j < sDataset2.getItemCount(i); j++) {
            newIndex = ySymbolicValuesCombined.indexOf(sDataset2.getYSymbolicValue(i, j));
            sDataset2.setYValue(i, j, new Integer(newIndex));
        }
    }

    // Set the new list of symbolic value on the two data sets
    final String[] ySymbolicValuesCombinedA = new String[ySymbolicValuesCombined.size()];
    ySymbolicValuesCombined.toArray(ySymbolicValuesCombinedA);
    sDataset1.setYSymbolicValues(ySymbolicValuesCombinedA);
    sDataset2.setYSymbolicValues(ySymbolicValuesCombinedA);

    return ySymbolicValuesCombinedA;
}

From source file:com.doculibre.constellio.services.FederationServicesImpl.java

private static void addIncludedCollections(RecordCollection ownerCollection,
        List<RecordCollection> allIncludedCollections) {
    for (RecordCollection includedCollection : ownerCollection.getIncludedCollections()) {
        if (!allIncludedCollections.contains(includedCollection)) {
            allIncludedCollections.add(includedCollection);
            // Recursive call
            addIncludedCollections(includedCollection, allIncludedCollections);
        }//from w w w. java2s.  co m
    }
}

From source file:dsll.pinterest.crawler.Reduce.java

private static Text updateBoardContent(String url, DBCollection baordsCollection)
        throws JSONException, IOException {
    String id = url.split("/")[4];
    DBCursor c = baordsCollection.find(new BasicDBObject("ID", id));
    DBObject oldPin = c.next();/* w  w  w.  ja v  a2  s .co  m*/
    JSONArray oldPins = new JSONArray(oldPin.get("pins").toString());

    Elements pinsCont = Jsoup.connect(url).get().select("div[class=pinWrapper]");
    // new pins
    JSONArray pins = new JSONArray();
    for (Element pinCont : pinsCont) {
        JSONObject pin = new JSONObject();
        pin.append("src", pinCont.select("div[class=pinHolder]>a").first().attr("href"));
        pins.put(pin);
    }

    List<String> oldPinURL = new ArrayList<String>();
    for (int i = 0; i < oldPins.length(); i++) {
        oldPinURL.add(oldPins.getJSONObject(i).getString("src"));
    }

    for (int i = 0; i < pins.length(); i++) {
        if (oldPinURL.contains(pins.getJSONObject(i).getString("src"))) {
            continue;
        }
        oldPins.put(pins.getJSONObject(i));
    }

    BasicDBObject newAttr = new BasicDBObject();
    newAttr.append("pins", oldPins);
    BasicDBObject update = new BasicDBObject().append("$set", newAttr);

    baordsCollection.update(new BasicDBObject("ID", id), update);
    return new Text("baord " + id + " updated...");
}

From source file:org.fastj.fit.tool.JSONHelper.java

public static Object jsonValue(String path, Map<String, Object> jo) throws DataInvalidException {
    //find(), data(), loop(), unique(), asc(), desc()
    String regex = "^[\\S\\s]*\\[((find|data|loop|unique|asc|desc)\\(\\))\\][\\S\\s]*$";
    String regex1 = "\\[((find|data|loop|unique|asc|desc)\\(\\))\\]";

    if (path.matches(regex)) {
        Matcher m = Pattern.compile(regex1).matcher(path);
        String op = null;/* w w  w . j  a va2 s.c om*/
        if (m.find()) {
            op = m.group(2);
        }

        if (m.find())
            throw new DataInvalidException("JSON path invalid: more op.");
        String sizePath = path.replaceAll(regex1, "[size()]");
        Object leno = jsonValueInner(sizePath, jo);
        if ("nil".equals(leno) || leno == null) {
            if ("loop".equals(op) || "find".equals(op))
                return new ArrayList<>();
            return "nil";
        }

        int lsize = (Integer) leno;

        List<Object> vl = new ArrayList<>();
        for (int i = 0; i < lsize; i++) {
            String npath = path.replaceAll(regex1, "[" + i + "]");
            Object o = jsonValueInner(npath, jo);
            if (!"nil".equals(o) && !"null".equals(o) && null != o) {
                vl.add(o);
            }
        }

        switch (op) {
        case "loop":
        case "find":
            return vl;
        case "data":
            StringBuilder buff = new StringBuilder("@data:");
            for (Object o : vl) {
                buff.append(String.valueOf(o)).append(",");
            }
            if (buff.charAt(buff.length() - 1) == ',')
                buff.deleteCharAt(buff.length() - 1);
            return buff.toString();
        case "unique":
            List<Object> chkl = new ArrayList<Object>();
            for (Object o : vl) {
                if (chkl.contains(o))
                    return "false";
                chkl.add(o);
            }
            return "true";
        case "asc":
            List<String> svl3 = new ArrayList<>();
            for (int i = 0; i < vl.size(); i++) {
                svl3.add(String.valueOf(vl.get(i)));
            }
            List<String> svl4 = new ArrayList<>();
            svl4.addAll(svl3);
            Collections.sort(svl4);

            for (int i = 0; i < svl3.size(); i++) {
                if (svl3.get(i).equals(svl4.get(i))) {
                    continue;
                } else {
                    return "false";
                }
            }

            return "true";
        case "desc":
            List<String> svl = new ArrayList<>();
            for (int i = 0; i < vl.size(); i++) {
                svl.add(String.valueOf(vl.get(i)));
            }
            List<String> svl2 = new ArrayList<>();
            svl2.addAll(svl);
            Collections.sort(svl2);

            int len = svl.size();
            for (int i = 0; i < svl.size(); i++) {
                if (svl.get(i).equals(svl2.get(len - i - 1))) {
                    continue;
                } else {
                    return "false";
                }
            }

            return "true";
        default:
            return "nil";
        }
    } else {
        return jsonValueInner(path, jo);
    }
}