Example usage for org.apache.commons.collections15 ListUtils intersection

List of usage examples for org.apache.commons.collections15 ListUtils intersection

Introduction

In this page you can find the example usage for org.apache.commons.collections15 ListUtils intersection.

Prototype

public static <E> List<E> intersection(final List<? extends E> list1, final List<? extends E> list2) 

Source Link

Document

Returns a new list containing all elements that are contained in both given lists.

Usage

From source file:de.tudarmstadt.ukp.dkpro.wsd.graphconnectivity.iterative.wikipedia.algorithm.LinkInformationSequentialDisambiguation.java

private double computeLinkMeasureSimilarity(String target0, String target1) throws SimilarityException {
    if (target0.equals(target1)) {
        return 1.0;
    }//from   w ww. j  av  a2s.  co m

    List<String> linksA;
    List<String> linksB;
    try {
        linksA = getIncomingLinks(target0);
        linksB = getIncomingLinks(target1);
    } catch (Exception e) {
        throw new SimilarityException();
    }

    int linksBoth = ListUtils.intersection(linksA, linksB).size();

    double a = Math.log(linksA.size());
    double b = Math.log(linksB.size());
    double ab = Math.log(linksBoth);
    double m = Math.log(linkInformationReader.getNumberOfSenses());

    double sr = (Math.max(a, b) - ab) / (m - Math.min(a, b));

    if (Double.isNaN(sr) || Double.isInfinite(sr) || sr > 1) {
        sr = 1;
    }

    sr = 1 - sr;

    return sr;

}

From source file:opendial.inference.exact.VariableElimination.java

/**
 * In case of overlap between the query variables and the evidence (this happens
 * when a variable specified in the evidence also appears in the query), extends 
 * the distribution to add the evidence assignment pairs.
 * /*from  w  ww . j a  va 2  s.co  m*/
 * @param query the query
 * @param distribution the computed distribution
 */
private DoubleFactor addEvidencePairs(DoubleFactor factor, Query query) {

    List<String> inter = ListUtils.intersection(new ArrayList<String>(query.getQueryVars()),
            new ArrayList<String>(query.getEvidence().getVariables()));

    if (!inter.isEmpty()) {
        DoubleFactor newFactor = new DoubleFactor();
        for (Assignment a : factor.getMatrix().keySet()) {
            Assignment assign = new Assignment(a, query.getEvidence().getTrimmed(inter));
            newFactor.addEntry(assign, factor.getProbEntry(a), factor.getUtilityEntry(a));
        }
        return newFactor;
    } else {
        return factor;
    }
}

From source file:org.dllearner.utilities.QueryUtils.java

public Set<Triple> extractTriplePattern(Query query, boolean ignoreOptionals) {
    triplePattern = new HashSet<>();
    optionalTriplePattern = new HashSet<>();

    query.getQueryPattern().visit(this);

    //postprocessing: triplepattern in OPTIONAL clause
    if (!ignoreOptionals) {
        if (query.isSelectType()) {
            for (Triple t : optionalTriplePattern) {
                if (!ListUtils.intersection(new ArrayList<>(VarUtils.getVars(t)), query.getProjectVars())
                        .isEmpty()) {//  w  w w  .ja  va 2s. c  o m
                    triplePattern.add(t);
                }
            }
        }
    }
    return triplePattern;
}

From source file:vnreal.algorithms.samples.SimpleDijkstraAlgorithm.java

@Override
protected boolean process(final VirtualLink p) {
    final SubstrateNode srcSnode;
    final SubstrateNode dstSnode;

    processedLinks++; // increase number of processed.

    VirtualNode srcVnode = ((VirtualNetwork) stack.getLayer(p.getLayer())).getSource(p);
    VirtualNode dstVnode = ((VirtualNetwork) stack.getLayer(p.getLayer())).getDest(p);

    // 1. Map source node.
    List<SubstrateNode> srcCandidates = null;
    for (AbstractDemand dem : srcVnode) {
        if (srcCandidates == null)
            srcCandidates = findFulfillingNodes(dem);
        else/*  ww w. jav  a 2s.  co m*/
            // Nodes that fulfill all requirements!
            srcCandidates = ListUtils.intersection(srcCandidates, findFulfillingNodes(dem));
    }

    if (srcCandidates.isEmpty()) {
        System.out.println("Cannot find source for " + p);
        return true;
    } else {
        srcSnode = srcCandidates.get(0);
    }

    // 2. Map destination node.
    List<SubstrateNode> dstCandidates = null;
    for (AbstractDemand dem : dstVnode) {
        if (dstCandidates == null)
            dstCandidates = findFulfillingNodes(dem);
        else
            // Nodes that fulfill all requirements!
            dstCandidates = ListUtils.intersection(dstCandidates, findFulfillingNodes(dem));
    }

    if (dstCandidates.isEmpty()) {
        System.out.println("Cannot find destination for " + p);
        return true;
    } else {
        dstSnode = dstCandidates.get(0);
    }

    // 3. Build node filter predicate
    // Predicate<SubstrateNode> nodePredicate = new
    // Predicate<SubstrateNode>() {
    // @Override
    // public boolean evaluate(SubstrateNode n) {
    // if (n.equals(srcSnode) || n.equals(dstSnode))
    // return true; // Always include these!

    // FIXME For now, we ignore requirements on intermediate nodes!
    // for (AbstractRequest req : p) {
    // if (req instanceof INodeConstraint) {
    // if (!findNodeResource(req, n))
    // return false;
    // // Exclude nodes that do not fulfill
    // // all requirements.
    // }
    // }

    // return true;
    // }

    // private boolean findNodeResource(AbstractRequest req,
    // SubstrateNode n) {
    // for (AbstractResource res : n)
    // if (res.accepts(req) && res.fulfills(req))
    // return true;
    //
    // return false;
    // }
    // };

    // 3. Build link filter predicate
    // Predicate<SubstrateLink> linkPredicate = new
    // Predicate<SubstrateLink>() {
    // @Override
    // public boolean evaluate(SubstrateLink l) {
    // for (AbstractDemand dem : p) {
    //
    // if (!findLinkResource(dem, l))
    // return false;
    // // Exclude links that do not fulfill
    // // all requirements.
    // }
    // return true;
    // }
    //
    // private boolean findLinkResource(AbstractDemand dem, SubstrateLink l)
    // {
    // for (AbstractResource res : l)
    // if (res.accepts(dem) && res.fulfills(dem))
    // return true;
    //
    // return false;
    // }
    // };

    // 4. Do the filtering
    // GraphFilter filter = new GraphFilter(nodePredicate, linkPredicate);

    // 5. Search for path in filtered substrate using Dijkstra
    DijkstraShortestPath<SubstrateNode, SubstrateLink> shortestPath;
    shortestPath = new DijkstraShortestPath<SubstrateNode, SubstrateLink>(
            // filter.transform(
            stack.getSubstrate()
    // )
    );
    List<SubstrateLink> path = shortestPath.getPath(srcSnode, dstSnode);

    // No path was found
    if (path.isEmpty()) {
        System.out.println("No path found for " + p);
        return true;
    }

    // 6. Perform virtual node mapping (VNM) for source.
    vnm(srcVnode, srcSnode);

    // 7. Perform virtual node mapping (VNM) for destination.
    vnm(dstVnode, dstSnode);

    // 8. Perform virtual link mapping (VLM) for each link in the path.
    vlm(p, path);

    // If we get here, we succeeded with this link.
    mappedLinks++;

    return true; // Only return false to interrupt the algorithm!!
}