<commit_before>/*
 * #%L
 * elk-IOReasoner
 * 
 * $Id$
 * $HeadURL$
 * %%
 * Copyright (C) 2011 Oxford University Computing Laboratory
 * %%
 * 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%
 */
package org.semanticweb.elk.cli;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

import junit.framework.TestCase;

import org.semanticweb.elk.owl.implementation.ElkObjectFactoryImpl;
import org.semanticweb.elk.owl.interfaces.ElkClass;
import org.semanticweb.elk.owl.interfaces.ElkObjectFactory;
import org.semanticweb.elk.owl.interfaces.ElkObjectProperty;
import org.semanticweb.elk.owl.iris.ElkFullIri;
import org.semanticweb.elk.owl.iris.ElkIri;
import org.semanticweb.elk.owl.parsing.javacc.ParseException;
import org.semanticweb.elk.owl.visitors.ElkClassExpressionVisitor;
import org.semanticweb.elk.owl.visitors.ElkEntityVisitor;
import org.semanticweb.elk.owl.visitors.ElkObjectVisitor;
import org.semanticweb.elk.reasoner.indexing.OntologyIndex;
import org.semanticweb.elk.reasoner.indexing.hierarchy.IndexedClassExpression;
import org.semanticweb.elk.reasoner.indexing.hierarchy.IndexedPropertyChain;
import org.semanticweb.elk.reasoner.taxonomy.ClassNode;
import org.semanticweb.elk.reasoner.taxonomy.ClassTaxonomy;

public class ReasonerTest extends TestCase {

	final ElkObjectFactory objectFactory = new ElkObjectFactoryImpl();

	public ReasonerTest(String testName) {
		super(testName);
	}

	public void testExistentials() throws InterruptedException,
			ExecutionException, ParseException, IOException {

		IOReasoner IOReasoner = new IOReasoner();
		IOReasoner.loadOntologyFromString(""//
				+ "Prefix( : = <http://example.org/> )" + "Ontology("//
				+ "EquivalentClasses(:B :C)"//
				+ "SubClassOf(:A ObjectSomeValuesFrom(:R :B))"//
				+ "SubClassOf(ObjectSomeValuesFrom(:S :C) :D)"//
				+ "SubObjectPropertyOf(:R :S)"//
				+ "ObjectPropertyDomain(:S :E)"//
				+ ")"//
		);

		ElkClass a = objectFactory.getClass(new ElkFullIri(
				"http://example.org/A"));
		ElkClass d = objectFactory.getClass(new ElkFullIri(
				"http://example.org/D"));
		ElkClass e = objectFactory.getClass(new ElkFullIri(
				"http://example.org/E"));
		ElkObjectProperty r = objectFactory.getObjectProperty(new ElkFullIri(
				"http://example.org/R"));
		ElkObjectProperty s = objectFactory.getObjectProperty(new ElkFullIri(
				"http://example.org/S"));

		IOReasoner.classify();
		ClassTaxonomy taxonomy = IOReasoner.getTaxonomy();

		OntologyIndex index = IOReasoner.getOntologyIndex();

		IndexedPropertyChain R = index.getIndexed(r);
		IndexedPropertyChain S = index.getIndexed(s);

		assertTrue("R subrole S", R.getToldSuperProperties().contains(S));
		assertTrue("S superrole R", S.getToldSubProperties().contains(R));
		assertTrue("A contains D", taxonomy.getNode(a).getDirectSuperNodes()
				.contains(taxonomy.getNode(d)));
		assertTrue("A contains E", taxonomy.getNode(a).getDirectSuperNodes()
				.contains(taxonomy.getNode(e)));
	}

	public void testConjunctions() throws InterruptedException,
			ExecutionException, ParseException, IOException {

		final IOReasoner IOReasoner = new IOReasoner();
		IOReasoner.loadOntologyFromString("Prefix( : = <http://example.org/> )"
				+ "Ontology(" + "SubClassOf(:A :B)" + "SubClassOf(:A :C)"
				+ "SubClassOf(:A :D)"
				+ "SubClassOf(ObjectIntersectionOf(:B :C :D) :E)" + ")");

		ElkClass a = objectFactory.getClass(new ElkFullIri(
				"http://example.org/A"));
		ElkClass b = objectFactory.getClass(new ElkFullIri(
				"http://example.org/B"));
		ElkClass c = objectFactory.getClass(new ElkFullIri(
				"http://example.org/C"));
		ElkClass d = objectFactory.getClass(new ElkFullIri(
				"http://example.org/D"));
		ElkClass e = objectFactory.getClass(new ElkFullIri(
				"http://example.org/E"));

		OntologyIndex index = IOReasoner.getOntologyIndex();

		IndexedClassExpression A = index.getIndexed(a);
		IndexedClassExpression B = index.getIndexed(b);
		IndexedClassExpression C = index.getIndexed(c);
		IndexedClassExpression D = index.getIndexed(d);
		IndexedClassExpression E = index.getIndexed(e);

		assertTrue("A SubClassOf B",
				A.getToldSuperClassExpressions().contains(B));
		assertTrue("A SubClassOf C",
				A.getToldSuperClassExpressions().contains(C));
		assertTrue("A SubClassOf D",
				A.getToldSuperClassExpressions().contains(D));
		assertFalse("A SubClassOf E", A.getToldSuperClassExpressions()
				.contains(E));

		IOReasoner.classify();

		ClassTaxonomy taxonomy = IOReasoner.getTaxonomy();
		ClassNode aNode = taxonomy.getNode(a);

		assertTrue("A contains B",
				aNode.getDirectSuperNodes().contains(taxonomy.getNode(b)));
		assertTrue("A contains C",
				aNode.getDirectSuperNodes().contains(taxonomy.getNode(c)));
		assertTrue("A contains D",
				aNode.getDirectSuperNodes().contains(taxonomy.getNode(d)));
		assertTrue("A contains E",
				aNode.getDirectSuperNodes().contains(taxonomy.getNode(e)));
	}

	public void testPropertyChains() throws ParseException, IOException {
		IOReasoner IOReasoner = new IOReasoner();
		IOReasoner
				.loadOntologyFromString(""//
						+ "Prefix( : = <http://example.org/> )"//
						+ "Prefix( owl: = <http://www.w3.org/2002/07/owl#> )"//
						+ "Ontology("//
						+ "SubClassOf(:A ObjectSomeValuesFrom(:R1 :B))"//
						+ "SubClassOf(:B ObjectSomeValuesFrom(:R2 :C))"//
						+ "SubClassOf(:C ObjectSomeValuesFrom(:R3 :D))"//
						+ "SubClassOf(:D ObjectSomeValuesFrom(:R4 :E))"//
						+ "SubClassOf(ObjectIntersectionOf(owl:Thing ObjectSomeValuesFrom(:T owl:Thing)) :X)"//
						+ "SubObjectPropertyOf(ObjectPropertyChain(:R3 :R4) :S)"//
						+ "SubObjectPropertyOf(ObjectPropertyChain(:R1 :R2 :S) :T)"//
						+ ")"//
				);

		IOReasoner.classify();

		ClassTaxonomy taxonomy = IOReasoner.getTaxonomy();
		ClassNode aNode = taxonomy.getNode(objectFactory
				.getClass(new ElkFullIri("http://example.org/A")));
		assertTrue(
				"A SubClassOf X",
				aNode.getDirectSuperNodes().contains(
						taxonomy.getNode(objectFactory.getClass(new ElkFullIri(
								"http://example.org/X")))));
	}

	public void testAncestors() throws InterruptedException,
			ExecutionException, ParseException, IOException {

		final IOReasoner IOReasoner = new IOReasoner();
		IOReasoner.loadOntologyFromString("Prefix( : = <http://example.org/> )"
				+ "Ontology(" + "SubClassOf(:A :B)" + "SubClassOf(:A :C)"
				+ "SubClassOf(:B :D)" + "SubClassOf(:C :D))");

		ElkClass a = objectFactory.getClass(new ElkFullIri(
				"http://example.org/A"));
		ElkClass b = objectFactory.getClass(new ElkFullIri(
				"http://example.org/B"));
		ElkClass c = objectFactory.getClass(new ElkFullIri(
				"http://example.org/C"));<commit_msg>commented out role chain test<commit_after>/*
 * #%L
 * elk-IOReasoner
 * 
 * $Id$
 * $HeadURL$
 * %%
 * Copyright (C) 2011 Oxford University Computing Laboratory
 * %%
 * 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%
 */
package org.semanticweb.elk.cli;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

import junit.framework.TestCase;

import org.semanticweb.elk.owl.implementation.ElkObjectFactoryImpl;
import org.semanticweb.elk.owl.interfaces.ElkClass;
import org.semanticweb.elk.owl.interfaces.ElkObjectFactory;
import org.semanticweb.elk.owl.interfaces.ElkObjectProperty;
import org.semanticweb.elk.owl.iris.ElkFullIri;
import org.semanticweb.elk.owl.iris.ElkIri;
import org.semanticweb.elk.owl.parsing.javacc.ParseException;
import org.semanticweb.elk.owl.visitors.ElkClassExpressionVisitor;
import org.semanticweb.elk.owl.visitors.ElkEntityVisitor;
import org.semanticweb.elk.owl.visitors.ElkObjectVisitor;
import org.semanticweb.elk.reasoner.indexing.OntologyIndex;
import org.semanticweb.elk.reasoner.indexing.hierarchy.IndexedClassExpression;
import org.semanticweb.elk.reasoner.indexing.hierarchy.IndexedPropertyChain;
import org.semanticweb.elk.reasoner.taxonomy.ClassNode;
import org.semanticweb.elk.reasoner.taxonomy.ClassTaxonomy;

public class ReasonerTest extends TestCase {

	final ElkObjectFactory objectFactory = new ElkObjectFactoryImpl();

	public ReasonerTest(String testName) {
		super(testName);
	}

	public void testExistentials() throws InterruptedException,
			ExecutionException, ParseException, IOException {

		IOReasoner IOReasoner = new IOReasoner();
		IOReasoner.loadOntologyFromString(""//
				+ "Prefix( : = <http://example.org/> )" + "Ontology("//
				+ "EquivalentClasses(:B :C)"//
				+ "SubClassOf(:A ObjectSomeValuesFrom(:R :B))"//
				+ "SubClassOf(ObjectSomeValuesFrom(:S :C) :D)"//
				+ "SubObjectPropertyOf(:R :S)"//
				+ "ObjectPropertyDomain(:S :E)"//
				+ ")"//
		);

		ElkClass a = objectFactory.getClass(new ElkFullIri(
				"http://example.org/A"));
		ElkClass d = objectFactory.getClass(new ElkFullIri(
				"http://example.org/D"));
		ElkClass e = objectFactory.getClass(new ElkFullIri(
				"http://example.org/E"));
		ElkObjectProperty r = objectFactory.getObjectProperty(new ElkFullIri(
				"http://example.org/R"));
		ElkObjectProperty s = objectFactory.getObjectProperty(new ElkFullIri(
				"http://example.org/S"));

		IOReasoner.classify();
		ClassTaxonomy taxonomy = IOReasoner.getTaxonomy();

		OntologyIndex index = IOReasoner.getOntologyIndex();

		IndexedPropertyChain R = index.getIndexed(r);
		IndexedPropertyChain S = index.getIndexed(s);

		assertTrue("R subrole S", R.getToldSuperProperties().contains(S));
		assertTrue("S superrole R", S.getToldSubProperties().contains(R));
		assertTrue("A contains D", taxonomy.getNode(a).getDirectSuperNodes()
				.contains(taxonomy.getNode(d)));
		assertTrue("A contains E", taxonomy.getNode(a).getDirectSuperNodes()
				.contains(taxonomy.getNode(e)));
	}

	public void testConjunctions() throws InterruptedException,
			ExecutionException, ParseException, IOException {

		final IOReasoner IOReasoner = new IOReasoner();
		IOReasoner.loadOntologyFromString("Prefix( : = <http://example.org/> )"
				+ "Ontology(" + "SubClassOf(:A :B)" + "SubClassOf(:A :C)"
				+ "SubClassOf(:A :D)"
				+ "SubClassOf(ObjectIntersectionOf(:B :C :D) :E)" + ")");

		ElkClass a = objectFactory.getClass(new ElkFullIri(
				"http://example.org/A"));
		ElkClass b = objectFactory.getClass(new ElkFullIri(
				"http://example.org/B"));
		ElkClass c = objectFactory.getClass(new ElkFullIri(
				"http://example.org/C"));
		ElkClass d = objectFactory.getClass(new ElkFullIri(
				"http://example.org/D"));
		ElkClass e = objectFactory.getClass(new ElkFullIri(
				"http://example.org/E"));

		OntologyIndex index = IOReasoner.getOntologyIndex();

		IndexedClassExpression A = index.getIndexed(a);
		IndexedClassExpression B = index.getIndexed(b);
		IndexedClassExpression C = index.getIndexed(c);
		IndexedClassExpression D = index.getIndexed(d);
		IndexedClassExpression E = index.getIndexed(e);

		assertTrue("A SubClassOf B",
				A.getToldSuperClassExpressions().contains(B));
		assertTrue("A SubClassOf C",
				A.getToldSuperClassExpressions().contains(C));
		assertTrue("A SubClassOf D",
				A.getToldSuperClassExpressions().contains(D));
		assertFalse("A SubClassOf E", A.getToldSuperClassExpressions()
				.contains(E));

		IOReasoner.classify();

		ClassTaxonomy taxonomy = IOReasoner.getTaxonomy();
		ClassNode aNode = taxonomy.getNode(a);

		assertTrue("A contains B",
				aNode.getDirectSuperNodes().contains(taxonomy.getNode(b)));
		assertTrue("A contains C",
				aNode.getDirectSuperNodes().contains(taxonomy.getNode(c)));
		assertTrue("A contains D",
				aNode.getDirectSuperNodes().contains(taxonomy.getNode(d)));
		assertTrue("A contains E",
				aNode.getDirectSuperNodes().contains(taxonomy.getNode(e)));
	}

	/*
	public void testPropertyChains() throws ParseException, IOException {
		IOReasoner IOReasoner = new IOReasoner();
		IOReasoner
				.loadOntologyFromString(""//
						+ "Prefix( : = <http://example.org/> )"//
						+ "Prefix( owl: = <http://www.w3.org/2002/07/owl#> )"//
						+ "Ontology("//
						+ "SubClassOf(:A ObjectSomeValuesFrom(:R1 :B))"//
						+ "SubClassOf(:B ObjectSomeValuesFrom(:R2 :C))"//
						+ "SubClassOf(:C ObjectSomeValuesFrom(:R3 :D))"//
						+ "SubClassOf(:D ObjectSomeValuesFrom(:R4 :E))"//
						+ "SubClassOf(ObjectIntersectionOf(owl:Thing ObjectSomeValuesFrom(:T owl:Thing)) :X)"//
						+ "SubObjectPropertyOf(ObjectPropertyChain(:R3 :R4) :S)"//
						+ "SubObjectPropertyOf(ObjectPropertyChain(:R1 :R2 :S) :T)"//
						+ ")"//
				);

		IOReasoner.classify();

		ClassTaxonomy taxonomy = IOReasoner.getTaxonomy();
		ClassNode aNode = taxonomy.getNode(objectFactory
				.getClass(new ElkFullIri("http://example.org/A")));
		assertTrue(
				"A SubClassOf X",
				aNode.getDirectSuperNodes().contains(
						taxonomy.getNode(objectFactory.getClass(new ElkFullIri(
								"http://example.org/X")))));
	}
	*/

	public void testAncestors() throws InterruptedException,
			ExecutionException, ParseException, IOException {

		final IOReasoner IOReasoner = new IOReasoner();
		IOReasoner.loadOntologyFromString("Prefix( : = <http://example.org/> )"
				+ "Ontology(" + "SubClassOf(:A :B)" + "SubClassOf(:A :C)"
				+ "SubClassOf(:B :D)" + "SubClassOf(:C :D))");

		ElkClass a = objectFactory.getClass(new ElkFullIri(
				"http://example.org/A"));
		ElkClass b = objectFactory.getClass(new ElkFullIri(
				"http://example.org/B"));
		ElkClass c = objectFactory.getClass(new ElkFullIri(
				"http://example.org/C"));
{'fraction_non_alphanumeric': 0.14396995409653637, 'fraction_numerical': 0.003199332313256364, 'mean_word_length': 4.658795749704841, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '373799', 'n_tokens_mistral': 5420, 'n_tokens_neox': 4851, 'n_words': 869}