<commit_before>import java.net.URI;
import java.util.List;
import java.util.Vector;

import org.junit.Test;
import org.obda.query.domain.Atom;
import org.obda.query.domain.CQIE;
import org.obda.query.domain.DatalogProgram;
import org.obda.query.domain.Predicate;
import org.obda.query.domain.PredicateFactory;
import org.obda.query.domain.Term;
import org.obda.query.domain.TermFactory;
import org.obda.query.domain.imp.AtomImpl;
import org.obda.query.domain.imp.BasicPredicateFactoryImpl;
import org.obda.query.domain.imp.CQIEImpl;
import org.obda.query.domain.imp.DatalogProgramImpl;
import org.obda.query.domain.imp.TermFactoryImpl;
import org.obda.query.domain.imp.UndistinguishedVariable;
import org.obda.reformulation.dllite.DLRPerfectReformulator;
import org.obda.reformulation.dllite.QueryRewriter;
import org.obda.reformulation.domain.Assertion;

import junit.framework.TestCase;

public class UnificationTest2 extends TestCase {

	/**
	 * Test method for
	 * {@link org.obda.reformulation.dllite.DLRPerfectReformulator#rewrite(org.obda.query.domain.Query)}
	 * .
	 * 
	 * Check if MGU generation/application works properly with multiple atoms sharing variables
	 * 
	 * q(x,y) :- R(x,#) R(#,y), S(x,#)
	 * 
	 * @throws Exception
	 */
	@Test
	public void test_1() throws Exception {

		TermFactory factory = TermFactoryImpl.getInstance();
		PredicateFactory predFac = BasicPredicateFactoryImpl.getInstance();

		Term t1 = factory.createVariable("x");
		Term t2 = factory.createVariable("y");
		Term t3 = factory.createVariable("x");

		Predicate r1 = predFac.getPredicate(URI.create("R"), 2);
		Predicate r2 = predFac.getPredicate(URI.create("R"), 2);
		Predicate s = predFac.getPredicate(URI.create("S"), 2);
		Predicate p = predFac.getPredicate(URI.create("p"), 2);

		List<Term> terms1 = new Vector<Term>();
		terms1.add(t1);
		terms1.add(new UndistinguishedVariable());
		List<Term> terms2 = new Vector<Term>();
		terms2.add(new UndistinguishedVariable());
		terms2.add(t2);
		List<Term> terms3 = new Vector<Term>();
		terms3.add(t3);
		terms3.add(new UndistinguishedVariable());
		List<Term> terms4 = new Vector<Term>();
		terms4.add(t3.copy());
		terms4.add(t2.copy());

		Atom a1 = new AtomImpl(r1, terms1);
		Atom a2 = new AtomImpl(r2, terms2);
		Atom a3 = new AtomImpl(s, terms3);
		Atom head = new AtomImpl(p, terms4);

		Vector<Atom> body = new Vector<Atom>();
		body.add(a1);
		body.add(a2);
		body.add(a3);
		CQIE query = new CQIEImpl(head, body, true);
		DatalogProgram prog = new DatalogProgramImpl();
		prog.appendRule(query);

		List<Assertion> list = new Vector<Assertion>();
		QueryRewriter rew = new DLRPerfectReformulator(list);
		DatalogProgram aux = (DatalogProgram) rew.rewrite(prog);
<commit_msg>Rename the method name: getPredicate() into createPredicate(). Also, the creation of undistinguished variable is through the term factory.<commit_after>import java.net.URI;
import java.util.List;
import java.util.Vector;

import junit.framework.TestCase;

import org.junit.Test;
import org.obda.query.domain.Atom;
import org.obda.query.domain.CQIE;
import org.obda.query.domain.DatalogProgram;
import org.obda.query.domain.Predicate;
import org.obda.query.domain.PredicateFactory;
import org.obda.query.domain.Term;
import org.obda.query.domain.imp.AtomImpl;
import org.obda.query.domain.imp.BasicPredicateFactoryImpl;
import org.obda.query.domain.imp.CQIEImpl;
import org.obda.query.domain.imp.DatalogProgramImpl;
import org.obda.query.domain.imp.TermFactoryImpl;
import org.obda.reformulation.dllite.DLRPerfectReformulator;
import org.obda.reformulation.dllite.QueryRewriter;
import org.obda.reformulation.domain.Assertion;

public class UnificationTest2 extends TestCase {

	/**
	 * Test method for
	 * {@link org.obda.reformulation.dllite.DLRPerfectReformulator#rewrite(org.obda.query.domain.Query)}
	 * .
	 *
	 * Check if MGU generation/application works properly with multiple atoms sharing variables
	 *
	 * q(x,y) :- R(x,#) R(#,y), S(x,#)
	 *
	 * @throws Exception
	 */
	@Test
	public void test_1() throws Exception {

		TermFactoryImpl factory = TermFactoryImpl.getInstance();
		PredicateFactory predFac = BasicPredicateFactoryImpl.getInstance();

		Term t1 = factory.createVariable("x");
		Term t2 = factory.createVariable("y");
		Term t3 = factory.createVariable("x");

		Predicate r1 = predFac.createPredicate(URI.create("R"), 2);
		Predicate r2 = predFac.createPredicate(URI.create("R"), 2);
		Predicate s = predFac.createPredicate(URI.create("S"), 2);
		Predicate p = predFac.createPredicate(URI.create("p"), 2);

		List<Term> terms1 = new Vector<Term>();
		terms1.add(t1);
		terms1.add(factory.createUndistinguishedVariable());
		List<Term> terms2 = new Vector<Term>();
		terms2.add(factory.createUndistinguishedVariable());
		terms2.add(t2);
		List<Term> terms3 = new Vector<Term>();
		terms3.add(t3);
		terms3.add(factory.createUndistinguishedVariable());
		List<Term> terms4 = new Vector<Term>();
		terms4.add(t3.copy());
		terms4.add(t2.copy());

		Atom a1 = new AtomImpl(r1, terms1);
		Atom a2 = new AtomImpl(r2, terms2);
		Atom a3 = new AtomImpl(s, terms3);
		Atom head = new AtomImpl(p, terms4);

		Vector<Atom> body = new Vector<Atom>();
		body.add(a1);
		body.add(a2);
		body.add(a3);
		CQIE query = new CQIEImpl(head, body, true);
		DatalogProgram prog = new DatalogProgramImpl();
		prog.appendRule(query);

		List<Assertion> list = new Vector<Assertion>();
		QueryRewriter rew = new DLRPerfectReformulator(list);
		DatalogProgram aux = (DatalogProgram) rew.rewrite(prog);

{'fraction_non_alphanumeric': 0.138205499276411, 'fraction_numerical': 0.01447178002894356, 'mean_word_length': 5.129711751662971, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4043115', 'n_tokens_mistral': 2071, 'n_tokens_neox': 1911, 'n_words': 376}