|
| 1 | +/* |
| 2 | + * This file is part of the ONT API. |
| 3 | + * The contents of this file are subject to the LGPL License, Version 3.0. |
| 4 | + * Copyright (c) 2020, The University of Manchester, owl.cs group. |
| 5 | + * |
| 6 | + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. |
| 7 | + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 8 | + * You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/. |
| 9 | + * |
| 10 | + * Alternatively, the contents of this file may be used under the terms of the Apache License, Version 2.0 in which case, the provisions of the Apache License Version 2.0 are applicable instead of those above. |
| 11 | + * 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 |
| 12 | + * 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. |
| 13 | + */ |
| 14 | + |
| 15 | +package com.github.owlcs.ontapi.internal.searchers.axioms; |
| 16 | + |
| 17 | +import com.github.owlcs.ontapi.config.AxiomsSettings; |
| 18 | +import com.github.owlcs.ontapi.internal.AxiomTranslator; |
| 19 | +import com.github.owlcs.ontapi.internal.ONTObject; |
| 20 | +import com.github.owlcs.ontapi.internal.ONTObjectFactory; |
| 21 | +import com.github.owlcs.ontapi.internal.WriteHelper; |
| 22 | +import com.github.owlcs.ontapi.jena.model.OntModel; |
| 23 | +import com.github.owlcs.ontapi.jena.model.OntStatement; |
| 24 | +import org.apache.jena.rdf.model.Resource; |
| 25 | +import org.apache.jena.util.iterator.ExtendedIterator; |
| 26 | +import org.semanticweb.owlapi.model.HasSubject; |
| 27 | +import org.semanticweb.owlapi.model.OWLAxiom; |
| 28 | +import org.semanticweb.owlapi.model.OWLObject; |
| 29 | + |
| 30 | +/** |
| 31 | + * Created by @ssz on 16.05.2020. |
| 32 | + * |
| 33 | + * @param <A> - {@link OWLAxiom} and {@link HasSubject} |
| 34 | + * @param <S> - {@link OWLObject} |
| 35 | + */ |
| 36 | +abstract class AssertionBySubject<A extends OWLAxiom & HasSubject<S>, S extends OWLObject> extends BaseByObject<A, S> { |
| 37 | + |
| 38 | + @Override |
| 39 | + public final ExtendedIterator<ONTObject<A>> listONTAxioms(S subject, |
| 40 | + OntModel model, |
| 41 | + ONTObjectFactory factory, |
| 42 | + AxiomsSettings config) { |
| 43 | + return listONTAxioms(subject, getTranslator(), model, factory, config); |
| 44 | + } |
| 45 | + |
| 46 | + private ExtendedIterator<ONTObject<A>> listONTAxioms(S subject, |
| 47 | + AxiomTranslator<A> translator, |
| 48 | + OntModel model, |
| 49 | + ONTObjectFactory factory, |
| 50 | + AxiomsSettings config) { |
| 51 | + ExtendedIterator<OntStatement> res = listBySubject(model, toResource(subject)) |
| 52 | + .filterKeep(x -> translator.testStatement(x, config)); |
| 53 | + return translate(translator, res, factory, config); |
| 54 | + } |
| 55 | + |
| 56 | + Resource toResource(S subject) { |
| 57 | + return WriteHelper.toResource(subject); |
| 58 | + } |
| 59 | + |
| 60 | + abstract AxiomTranslator<A> getTranslator(); |
| 61 | +} |
0 commit comments