All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.mindswap.pellet.jena.graph.query.SingleVarQueryHandler Maven / Gradle / Ivy

The newest version!
// Copyright (c) 2006 - 2008, Clark & Parsia, LLC. 
// This source code is available under the terms of the Affero General Public License v3.
//
// Please see LICENSE.txt for full license terms, including the availability of proprietary exceptions.
// Questions, comments, or requests for clarification: [email protected]

package org.mindswap.pellet.jena.graph.query;

import java.util.Set;

import org.mindswap.pellet.KnowledgeBase;
import org.mindswap.pellet.jena.PelletInfGraph;
import org.mindswap.pellet.jena.graph.loader.GraphLoader;

import aterm.ATermAppl;

import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.graph.Triple;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;

abstract class SingleVarQueryHandler extends TripleQueryHandler {
	public abstract Set getResults(KnowledgeBase kb, ATermAppl term);
	
	@Override
	public final boolean contains(KnowledgeBase kb, GraphLoader loader, Node subj, Node pred, Node obj) {
		Node n = subj.isConcrete() ? obj : subj;
		return !getResults( kb, loader.node2term( n ) ).isEmpty();
	}
	
	@Override
	public final ExtendedIterator find(KnowledgeBase kb, PelletInfGraph pellet, Node subj, Node pred, Node obj) {
		Node n = subj.isConcrete() ? obj : subj;
		Set results = getResults( kb, pellet.getLoader().node2term( n ) );
		return subj.isConcrete()
			? objectFiller( subj, pred, results )
			: subjectFiller( results, pred, obj );
	}			
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy