Package org.jrdf.graph.global.molecule

Examples of org.jrdf.graph.global.molecule.Molecule


        SortedSet<Molecule> moleculeSet = subMolecules.get(triple);
        if (moleculeSet == null) {
            moleculeSet = new TreeSet<Molecule>(moleculeComparator);
        }
        if (isDoubleLinkedTriple(newTriple)) {
            Molecule newMolecule = new MoleculeImpl(moleculeComparator, newTriple);
            moleculeSet.add(newMolecule);
            ((MoleculeImpl) newMolecule).isTopLevel = false;
            subMolecules.put(triple, moleculeSet);
        } else {
            if (moleculeSet.isEmpty()) {
                Molecule newMolecule = new MoleculeImpl(moleculeComparator, newTriple);
                ((MoleculeImpl) newMolecule).isTopLevel = false;
                moleculeSet.add(newMolecule);
                subMolecules.put(triple, moleculeSet);
            } else {
                moleculeSet.last().add(newTriple);
View Full Code Here


            if (!triplesChecked.contains(currentTriple)) {
                Triple newStartingPoint = new FindEntryNodeImpl().find(graph, currentTriple);
                if (tripleComparator.compare(newStartingPoint, currentTriple) < 0) {
                    currentTriple = newStartingPoint;
                }
                Molecule molecule = moleculeFactory.createMolecule();
                molecule = molecule.add(currentTriple);
                triplesChecked.add(currentTriple);
                molecule = convertTripleToMolecule(molecule);
                molecules.add(molecule);
            }
        }
View Full Code Here

        triples.iterator().close();
        return molecule;
    }

    private Molecule addLinkedTriple(Molecule molecule, Triple triple) throws GraphException {
        Molecule subMolecule = moleculeFactory.createMolecule();
        subMolecule.add(triple);
        triplesChecked.add(triple);
        // Put submolecule inside molecule's head triple
        if (isDoubleLinkedTriple(molecule.getHeadTriple()) &&
            molecule.getHeadTriple().getObject().equals(triple.getSubject())) {
            getSubMolecule(subMolecule, triple);
            return molecule.add(molecule.getHeadTriple(), subMolecule);
            // Put molecule inside submolecule
        } else if (triple.getObject().equals(molecule.getHeadTriple().getSubject())) {
            getSubMolecule(subMolecule, triple);
            return subMolecule.add(triple, molecule);
            // Put submolecule inside molecule
        } else {
            getSubMolecule(subMolecule, triple);
            if (isDoubleLinkedTriple(triple)) {
                Set<Molecule> subMolecules = subMolecule.getSubMolecules(triple);
                for (Molecule newMole : subMolecules) {
                    molecule.add(triple, newMole);
                }
            }
            subMolecule.remove(triple);
            getNewRootTriples(molecule, triple);
            return molecule.add(triple, subMolecule);
        }
    }
View Full Code Here

    public Molecule merge(Molecule molecule1, Molecule molecule2) {
        if (subsumption.subsumes(molecule1, molecule2)) {
            SortedSet<Triple> newRootTriples = new TreeSet<Triple>(comparator);
            addRootTriples(molecule1, newRootTriples);
            addRootTriples(molecule2, newRootTriples);
            Molecule newMolecule = moleculeFactory.createMolecule(newRootTriples);
            Iterator<Triple> subMoleculeIter = newMolecule.getRootTriples();
            while (subMoleculeIter.hasNext()) {
                Triple currentTriple = subMoleculeIter.next();
                newMolecule.specialAdd(merge(currentTriple, molecule1, molecule2));
            }
            return newMolecule;
        } else {
            throw new IllegalArgumentException("Cannot merge molecules with different head triples.");
        }
View Full Code Here

            throw new IllegalArgumentException("Cannot merge molecules with different head triples.");
        }
    }

    public Molecule merge(Triple triple, Molecule molecule1, Molecule molecule2) {
        Molecule newMolecule = moleculeFactory.createMolecule();
        Iterator<Molecule> curr1Iterator = molecule1.getSubMolecules(triple).iterator();
        Iterator<Molecule> curr2Iterator = molecule2.getSubMolecules(triple).iterator();
        iterateAndMergeMolecules(newMolecule, triple, curr1Iterator, curr2Iterator);
        return newMolecule;
    }
View Full Code Here

    private void iterateAndMergeMolecules(Molecule newMolecule, Triple currentTriple,
        Iterator<Molecule> curr1Iterator, Iterator<Molecule> curr2Iterator) {
        boolean endIterator1 = curr1Iterator.hasNext();
        boolean endIterator2 = curr2Iterator.hasNext();
        Molecule currentMolecule1 = getNextFromIterator(curr1Iterator);
        Molecule currentMolecule2 = getNextFromIterator(curr2Iterator);
        while (endIterator1 || endIterator2) {
            int result = moleculeComparator.compare(currentMolecule1, currentMolecule2);
            if (result == 1) {
                endIterator1 = curr1Iterator.hasNext();
                currentMolecule1 = addMolecule(newMolecule, currentTriple, currentMolecule1, curr1Iterator);
View Full Code Here

        }
    }

    private Molecule addMolecule(Molecule newMolecule, Triple currentTriple, Molecule currentMolecule,
        Iterator<Molecule> moleculeIterator) {
        Molecule tmpMolecule = currentMolecule;
        newMolecule.add(currentTriple, tmpMolecule);
        tmpMolecule = getNextFromIterator(moleculeIterator);
        return tmpMolecule;
    }
View Full Code Here

        tmpMolecule = getNextFromIterator(moleculeIterator);
        return tmpMolecule;
    }

    private Molecule getNextFromIterator(Iterator<Molecule> moleculeIterator) {
        Molecule tmpMolecule;
        if (moleculeIterator.hasNext()) {
            tmpMolecule = moleculeIterator.next();
        } else {
            tmpMolecule = NULL_MOLECULE;
        }
View Full Code Here

            findCorrespondingTriple(m1Roots, m2RootTriple, map);
            Set<Molecule> sm1s = m1.getSubMolecules(m2RootTriple);
            Set<Molecule> sm2s = m2.getSubMolecules(m2RootTriple);
            if (!sm1s.isEmpty() && !sm2s.isEmpty()) {
                if (sm1s.size() == 1 && sm2s.size() == 1) {
                    Molecule sm1 = sm1s.iterator().next();
                    Molecule sm2 = sm2s.iterator().next();
                    Map<BlankNode, BlankNode> curMap = startPopulateMap(sm1, sm2);
                    if (curMap.isEmpty()) {
                        return curMap;
                    } else {
                        for (Map.Entry<BlankNode, BlankNode> entry : curMap.entrySet()) {
View Full Code Here

            return null;
        }
    }

    private Molecule convertMolecule(Molecule molecule) {
        final Molecule newMolecule = convertRootTriples(molecule);
        final Iterator<Triple> triples = molecule.getRootTriples();
        while (triples.hasNext()) {
            final Triple triple = triples.next();
            final Set<Molecule> moleculeSet = molecule.getSubMolecules(triple);
            for (final Molecule subMolecule : moleculeSet) {
                final Molecule convertedSubMolecule = convertMolecule(subMolecule);
                newMolecule.add(convertTriple(triple), convertedSubMolecule);
            }
        }
        return newMolecule;
    }
View Full Code Here

TOP

Related Classes of org.jrdf.graph.global.molecule.Molecule

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.