it.unibz.inf.ontop.sesame.SesameBindingSet Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ontop-quest-sesame Show documentation
Show all versions of ontop-quest-sesame Show documentation
This is the Sesame API implementation based on Quest
package it.unibz.inf.ontop.sesame;
/*
* #%L
* ontop-quest-sesame
* %%
* Copyright (C) 2009 - 2014 Free University of Bozen-Bolzano
* %%
* Licensed 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.
* #L%
*/
import it.unibz.inf.ontop.model.Constant;
import it.unibz.inf.ontop.model.ObjectConstant;
import it.unibz.inf.ontop.model.TupleResultSet;
import it.unibz.inf.ontop.model.ValueConstant;
import it.unibz.inf.ontop.sesame.SesameHelper;
import org.openrdf.model.Value;
import org.openrdf.query.Binding;
import org.openrdf.query.BindingSet;
import org.openrdf.query.impl.BindingImpl;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
public class SesameBindingSet implements BindingSet {
private static final long serialVersionUID = -8455466574395305166L;
private TupleResultSet set = null;
private int count = 0;
private final Set bindingnames;
// private List signature;
private final SesameHelper helper = new SesameHelper();
public SesameBindingSet(TupleResultSet set, Set bindingnames) {
this.bindingnames = bindingnames;
// this.signature = signature;
this.set = set;
this.count = bindingnames.size();
}
@Override
public Binding getBinding(String bindingName) {
// return the Binding with bindingName
return createBinding(bindingName);
}
@Override
public Set getBindingNames() {
return bindingnames;
}
@Override
public Value getValue(String bindingName) {
return createBinding(bindingName).getValue();
}
private Binding createBinding(String bindingName) {
Value value = null;
try {
if (hasBinding(bindingName)) {
// int column = set.getSignature().indexOf(bindingName) + 1;
Constant c = set.getConstant(bindingName);
if (c == null) {
return null;
}
else {
if (c instanceof ValueConstant) {
value = SesameHelper.getLiteral((ValueConstant)c);
}
else {
value = SesameHelper.getResource((ObjectConstant)c);
}
}
}
return new BindingImpl(bindingName, value);
}
catch (Exception e) {
throw new RuntimeException(e);
}
// return null;
}
@Override
public boolean hasBinding(String bindingName) {
return bindingnames.contains(bindingName);
// try {
// return set.getSignature().contains(bindingName);
// } catch (Exception e) {
// e.printStackTrace();
// }
// return false;
}
@Override
public Iterator iterator() {
List allBindings = new LinkedList();
List bindings;
try {
bindings = set.getSignature();
for (String s : bindings)
allBindings.add(createBinding(s));
} catch (Exception e) {
e.printStackTrace();
}
return allBindings.iterator();
}
@Override
public int size() {
return count;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy