org.apache.jena.riot.other.GLib Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jena-arq Show documentation
Show all versions of jena-arq Show documentation
ARQ is a SPARQL 1.1 query engine for Apache Jena
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.jena.riot.other;
import java.util.Iterator ;
import org.apache.jena.atlas.iterator.Iter ;
import org.apache.jena.graph.Graph ;
import org.apache.jena.graph.Node ;
import org.apache.jena.graph.Triple ;
import org.apache.jena.sparql.core.Quad ;
import org.apache.jena.util.iterator.ExtendedIterator ;
/** A collection of Graph/Triple/Node related functions */
public class GLib
{
/** Convert null to Node.ANY */
public static Node nullAsAny(Node x) { return nullAsDft(x, Node.ANY) ; }
/** Convert null to some default Node */
public static Node nullAsDft(Node x, Node dft) { return x==null ? dft : x ; }
// DISTINCT means these are space using.
/** List the subjects in a graph (no duplicates) */
public static Iterator listSubjects(Graph graph)
{
ExtendedIterator iter = graph.find(Node.ANY, Node.ANY, Node.ANY) ;
return Iter.iter(iter).map(Triple::getSubject).distinct() ;
}
/** List the predicates in a graph (no duplicates) */
public static Iterator listPredicates(Graph graph)
{
ExtendedIterator iter = graph.find(Node.ANY, Node.ANY, Node.ANY) ;
return Iter.iter(iter).map(Triple::getPredicate).distinct() ;
}
/** List the objects in a graph (no duplicates) */
public static Iterator listObjects(Graph graph)
{
ExtendedIterator iter = graph.find(Node.ANY, Node.ANY, Node.ANY) ;
return Iter.iter(iter).map(Triple::getObject).distinct() ;
}
/** Project quads to triples */
public static Iter quads2triples(Iterator iter)
{
return Iter.iter(iter).map(Quad::asTriple) ;
}
/** Project quad to graphname */
public static Iterator quad2graphName(Iterator iter)
{ return Iter.map(iter, Quad::getGraph) ; }
/** Project quad to graphname */
public static Iterator quad2subject(Iterator iter)
{ return Iter.map(iter, Quad::getSubject) ; }
/** Project quad to predicate */
public static Iterator quad2predicate(Iterator iter)
{ return Iter.map(iter, Quad::getPredicate) ; }
/** Project quad to object */
public static Iterator quad2object(Iterator iter)
{ return Iter.map(iter, Quad::getObject) ; }
/** Project triple to subject */
public static Iterator triple2subject(Iterator iter)
{ return Iter.map(iter, Triple::getSubject) ; }
/** Project triple to predicate */
public static Iterator triple2predicate(Iterator iter)
{ return Iter.map(iter, Triple::getPredicate) ; }
/** Project triple to object */
public static Iterator triple2object(Iterator iter)
{ return Iter.map(iter, Triple::getObject) ; }
}