Package org.trippi

Examples of org.trippi.TripleIterator


    public static Set<RelationshipTuple> readRelationships(InputStream dsContent)
            throws TrippiException {
        Set<RelationshipTuple> tuples = new HashSet<RelationshipTuple>();

        TripleIterator iter = null;
        try {
            iter = TripleIteratorFactory.defaultInstance().fromStream(dsContent, RDFFormat.RDF_XML);
            Triple triple;
            while (iter.hasNext()) {
                triple = iter.next();
                tuples.add(RelationshipTuple.fromTriple(triple));
            }
        } finally {
            if (iter != null) {
                iter.close();
            }
        }
        return tuples;
    }
View Full Code Here


                map.put(MODEL.prefix, MODEL.uri);
            }
            map.put(RDF.prefix, RDF.uri);

            try {
                TripleIterator triples =
                        new FilteredTripleIterator(map, toAdd, true);
                triples.toStream(out, RDFFormat.RDF_XML, false);
            } catch (TrippiException e) {
                throw new GeneralException(e.getMessage(), e);
            }

            dsxml = new XMLDatastreamProcessor(dsId);
            Datastream newds = dsxml.getDatastream();
            newds.DatastreamAltIDs = new String[0];
            // formats for internal datastreams
            if (dsId.equals("RELS-EXT")) {
                newds.DSFormatURI = RELS_EXT1_0.uri;
            } else {
                if (dsId.equals("RELS-INT"))
                    newds.DSFormatURI = RELS_INT1_0.uri;
            }
            newds.DSMIME = "application/rdf+xml";
            //newds.DSControlGrp = "X"; set by XMLDatastreamProcessor instead
            newds.DSInfoType = null;
            newds.DSState = "A";
            newds.DSVersionable = false;
            newds.DSVersionID = dsId + ".0";
            newds.DSLabel = "Relationships";
            newds.DSCreateDT = Server.getCurrentDate(m_context);
            newds.DSLocation = null;
            newds.DSLocationType = null;
            newds.DSChecksumType = Datastream.getDefaultChecksumType();
            dsxml.setXMLContent(out.toByteArray());
            newds.DSSize = dsxml.getXMLContent().length;

            ValidationUtility.validateReservedDatastream(PID.getInstance(m_obj.getPid()),
                                                         newds.DatastreamID,
                                                         newds);
            addDatastream(newds, false);
        } else { // (relsDatastream != null)
            dsxml = new XMLDatastreamProcessor(relsDatastream);
            FilteredTripleIterator newIter = null;
            try {
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                TripleIterator iter =
                        TripleIteratorFactory.defaultInstance().fromStream(relsDatastream.getContentStream(),
                                                  RDFFormat.RDF_XML);
                newIter = new FilteredTripleIterator(iter, toAdd, true);
                newIter.toStream(out, RDFFormat.RDF_XML, false);
View Full Code Here

            return false;
        } else { // (relsExt != null)
            XMLDatastreamProcessor dsxml = new XMLDatastreamProcessor(relsDatastream);
            InputStream relsDatastreamIS = relsDatastream.getContentStream();

            TripleIterator iter = null;
            FilteredTripleIterator newIter = null;
            try {
                iter = TripleIteratorFactory.defaultInstance().fromStream(relsDatastreamIS, RDFFormat.RDF_XML);

                newIter = new FilteredTripleIterator(iter, toPurge, false);
View Full Code Here

        } catch (TrippiException e) {
            throw new MelcoeXacmlException("Error creating nodes for trippi query " + e.getMessage(), e);
        }

        try {
            TripleIterator it = RI.findTriples(s, p, null, 0);
            while (it.hasNext()) {
                Triple t = it.next();
                String pred = t.getPredicate().toString();

                Set<String> values = rels.get(pred);
                if (values == null) {
                    values = new HashSet<String>();
View Full Code Here

        } catch (TrippiException e) {
            throw new MelcoeXacmlException("Error creating nodes for trippi query " + e.getMessage(), e);
        }

        try {
            TripleIterator it = RI.findTriples(null, p, o, 0);
            while (it.hasNext()) {
                Triple t = it.next();
                String pred = t.getPredicate().toString();

                Set<String> values = rels.get(pred);
                if (values == null) {
                    values = new HashSet<String>();
View Full Code Here

                return res;
            }
            // check variable is s, p, o
            if (variable.length() == 1 && "spo".contains(variable)) {
                try {
                    TripleIterator triples = RI.findTriples(queryLang, query, 0, true);
                    if (triples != null ) {
                        while (triples.hasNext()) {
                            Triple triple = triples.next();
                            switch(variable.charAt(0)) {
                                case 's':
                                    res.add(triple.getSubject().stringValue());
                                    break;
                                case 'p':
View Full Code Here

            // assume the subject is the object as denoted by the pid
            subject = PID.toURI(pid);
        }
        try {
            RelationshipTuple[] tuples = m_management.getRelationships(context, subject, predicate);
            TripleIterator it = new TupleArrayTripleIterator(new ArrayList<RelationshipTuple>(Arrays.asList(tuples)));
            ByteArrayOutputStream out = new ByteArrayOutputStream();

            format = format.toLowerCase();
            RDFFormat outputFormat;
            MediaType mediaType;
            if (format.equalsIgnoreCase("xml") || format.equals("rdf/xml")) {
                outputFormat = RDFFormat.RDF_XML;
                mediaType = new MediaType("application", "rdf+xml");
            } else if (format.equals("n-triples") || format.equals("ntriples")) {
                outputFormat = RDFFormat.N_TRIPLES;
                mediaType = MediaType.TEXT_PLAIN_TYPE;
            } else if (format.equals("turtle")) {
                outputFormat = RDFFormat.TURTLE;
                mediaType = new MediaType("application", "x-turtle");
            } else if (format.equals("sparql")) {
                outputFormat = RDFFormat.SPARQL;
                mediaType = new MediaType("application", "sparql-results+xml");
            } else {
                throw new IllegalArgumentException("unknown format: " + format);
            }
            it.toStream(out, outputFormat);
            return Response.ok(out.toString("UTF-8"), mediaType).build();
        } catch (ServerException e) {
            return handleException(e, flash);
        } catch (TrippiException e) {
            return handleException(e, flash);
View Full Code Here

        }

        try{
            SubjectNode snode = new SimpleURIReference(new URI(resourceID));
            PredicateNode pnode = new SimpleURIReference(new URI(attribute));
            TripleIterator triples = m_resourceIndex.findTriples(snode, pnode, null, 0);
            results = new HashSet<String>();
            while (triples.hasNext()){
                Triple triple = triples.next();
                String object = triple.getObject().stringValue();
                results.add(object);
            }
        }
        catch (TrippiException e){
View Full Code Here

     * {@inheritDoc}
     */
    public void export(OutputStream out, RDFFormat format)
            throws ResourceIndexException {
        try {
            TripleIterator it = _writer.findTriples(null, null, null, 0);
            it.setAliasMap(_writer.getAliasMap());
            it.toStream(out, format);
        } catch (TrippiException e) {
            throw new ResourceIndexException("Unable to export RI", e);
        }
    }
View Full Code Here

    /**
     * Gets a Trippi TripleIterator for the given set.
     */
    private TripleIterator getTripleIterator(final Set<Triple> set) {
        return new TripleIterator() {

            private final Iterator<Triple> _iter = set.iterator();

            @Override
            public boolean hasNext() {
View Full Code Here

TOP

Related Classes of org.trippi.TripleIterator

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.