Search in sources :

Example 6 with DefaultAtom

use of fr.lirmm.graphik.graal.core.DefaultAtom in project graal by graphik-team.

the class AbstractDlgpListener method createsEquality.

@Override
public void createsEquality(Object term1, Object term2) {
    atom = new DefaultAtom(Predicate.EQUALITY, createTerm(term1), createTerm(term2));
    this.atomSet.add(atom);
}
Also used : DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom)

Example 7 with DefaultAtom

use of fr.lirmm.graphik.graal.core.DefaultAtom in project graal by graphik-team.

the class AbstractDlgpListener method createsAtom.

@Override
public void createsAtom(Object predicate, Object[] terms) {
    List<Term> list = new LinkedList<Term>();
    for (Object t : terms) {
        list.add(createTerm(t));
    }
    atom = new DefaultAtom(createPredicate(predicate, terms.length), list);
    this.atomSet.add(atom);
}
Also used : DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) Term(fr.lirmm.graphik.graal.api.core.Term) LinkedList(java.util.LinkedList)

Example 8 with DefaultAtom

use of fr.lirmm.graphik.graal.core.DefaultAtom in project graal by graphik-team.

the class Atom2SubstitutionConverterTest method githubIssue2variant1.

@Test
public void githubIssue2variant1() throws ParseException {
    // given
    Predicate p = DefaultPredicateFactory.instance().create("p", 1);
    Variable x = DefaultTermFactory.instance().createVariable("X");
    Variable y = DefaultTermFactory.instance().createVariable("Y");
    Atom queryAtom = new DefaultAtom(p, x);
    List<Term> ansList = new LinkedList<>();
    ansList.add(x);
    ansList.add(y);
    // when
    Converter<Atom, Substitution> converter = new Atom2SubstitutionConverter(queryAtom, ansList);
    Substitution s = null;
    try {
        s = converter.convert(DlgpParser.parseAtom("p(a)."));
    } catch (ConversionException e) {
        fail();
    }
    // then
    Constant a = DefaultTermFactory.instance().createConstant("a");
    assertEquals(a, s.createImageOf(x));
    assertEquals(y, s.createImageOf(y));
}
Also used : ConversionException(fr.lirmm.graphik.util.stream.converter.ConversionException) Variable(fr.lirmm.graphik.graal.api.core.Variable) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) Constant(fr.lirmm.graphik.graal.api.core.Constant) DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) Term(fr.lirmm.graphik.graal.api.core.Term) DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) Atom(fr.lirmm.graphik.graal.api.core.Atom) LinkedList(java.util.LinkedList) Predicate(fr.lirmm.graphik.graal.api.core.Predicate) Test(org.junit.Test)

Example 9 with DefaultAtom

use of fr.lirmm.graphik.graal.core.DefaultAtom in project graal by graphik-team.

the class Atom2SubstitutionConverterTest method basic.

@Test
public void basic() throws ParseException {
    // given
    Predicate p = DefaultPredicateFactory.instance().create("p", 1);
    Variable x = DefaultTermFactory.instance().createVariable("X");
    Atom queryAtom = new DefaultAtom(p, x);
    List<Term> ansList = new LinkedList<>();
    ansList.add(x);
    // when
    Converter<Atom, Substitution> converter = new Atom2SubstitutionConverter(queryAtom, ansList);
    Substitution s = null;
    try {
        s = converter.convert(DlgpParser.parseAtom("p(a)."));
    } catch (ConversionException e) {
        fail();
    }
    // then
    Constant a = DefaultTermFactory.instance().createConstant("a");
    assertEquals(a, s.createImageOf(x));
}
Also used : ConversionException(fr.lirmm.graphik.util.stream.converter.ConversionException) Variable(fr.lirmm.graphik.graal.api.core.Variable) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) Constant(fr.lirmm.graphik.graal.api.core.Constant) DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) Term(fr.lirmm.graphik.graal.api.core.Term) DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) Atom(fr.lirmm.graphik.graal.api.core.Atom) LinkedList(java.util.LinkedList) Predicate(fr.lirmm.graphik.graal.api.core.Predicate) Test(org.junit.Test)

Example 10 with DefaultAtom

use of fr.lirmm.graphik.graal.core.DefaultAtom in project graal by graphik-team.

the class DlgpWriterTest method writeConstant.

@Test
public void writeConstant() throws IOException {
    Term a = DefaultTermFactory.instance().createConstant("A");
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    DlgpWriter writer = new DlgpWriter(os);
    writer.write(new DefaultAtom(predicat, a));
    writer.flush();
    String s = new String(os.toByteArray(), "UTF-8");
    writer.close();
    char c = s.charAt(s.indexOf("(") + 1);
    Assert.assertTrue("Constant label does not begin with lower case.", Character.isLowerCase(c) || c == '<');
}
Also used : DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) Term(fr.lirmm.graphik.graal.api.core.Term) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Aggregations

DefaultAtom (fr.lirmm.graphik.graal.core.DefaultAtom)45 Predicate (fr.lirmm.graphik.graal.api.core.Predicate)25 Term (fr.lirmm.graphik.graal.api.core.Term)25 Atom (fr.lirmm.graphik.graal.api.core.Atom)21 Test (org.junit.Test)20 LinkedList (java.util.LinkedList)17 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)12 LinkedListRuleSet (fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)7 Rule (fr.lirmm.graphik.graal.api.core.Rule)7 RuleSet (fr.lirmm.graphik.graal.api.core.RuleSet)7 Variable (fr.lirmm.graphik.graal.api.core.Variable)6 ConversionException (fr.lirmm.graphik.util.stream.converter.ConversionException)6 Constant (fr.lirmm.graphik.graal.api.core.Constant)5 DefaultURI (fr.lirmm.graphik.util.DefaultURI)5 Pair (org.apache.commons.lang3.tuple.Pair)5 DefaultRule (fr.lirmm.graphik.graal.core.DefaultRule)4 AnalyserRuleSet (fr.lirmm.graphik.graal.rulesetanalyser.util.AnalyserRuleSet)4 RulesCompilation (fr.lirmm.graphik.graal.api.core.RulesCompilation)3