query) {
84 | return ConjunctiveQueryHelper.query(this, query);
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/src/main/java/edu/harvard/seas/pl/abcdatalog/engine/DatalogEngineWithProvenance.java:
--------------------------------------------------------------------------------
1 | package edu.harvard.seas.pl.abcdatalog.engine;
2 |
3 | /*-
4 | * #%L
5 | * AbcDatalog
6 | * %%
7 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
8 | * %%
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | *
12 | * 1. Redistributions of source code must retain the above copyright notice, this
13 | * list of conditions and the following disclaimer.
14 | *
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | *
19 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software without
21 | * specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
32 | * OF THE POSSIBILITY OF SUCH DAMAGE.
33 | * #L%
34 | */
35 |
36 | import edu.harvard.seas.pl.abcdatalog.ast.Clause;
37 | import edu.harvard.seas.pl.abcdatalog.ast.PositiveAtom;
38 |
39 | /**
40 | * A Datalog evaluation engine that retains fact provenance. Datalog engines are initialized with a
41 | * set of clauses that represent initial facts and rules that can be used to derive new facts. After
42 | * initialization, clients can query about whether certain facts are derivable.
43 | *
44 | * This engine also supports why-provenance queries; that is, querying for the justification for
45 | * why a fact was derived.
46 | */
47 | public interface DatalogEngineWithProvenance extends DatalogEngine {
48 |
49 | /**
50 | * Return the last rule used in the justification of the given atom. The returned rule should be
51 | * ground (variable-free). Return null if the given atom is not a fact or was not derived.
52 | *
53 | * A client can recursively invoke this method on the premises of the returned clause to build a
54 | * provenance tree.
55 | *
56 | * @param fact the fact
57 | * @return the last rule used to justify that fact
58 | */
59 | Clause getJustification(PositiveAtom fact);
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/edu/harvard/seas/pl/abcdatalog/engine/bottomup/AnnotatedAtom.java:
--------------------------------------------------------------------------------
1 | package edu.harvard.seas.pl.abcdatalog.engine.bottomup;
2 |
3 | /*-
4 | * #%L
5 | * AbcDatalog
6 | * %%
7 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
8 | * %%
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | *
12 | * 1. Redistributions of source code must retain the above copyright notice, this
13 | * list of conditions and the following disclaimer.
14 | *
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | *
19 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software without
21 | * specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
32 | * OF THE POSSIBILITY OF SUCH DAMAGE.
33 | * #L%
34 | */
35 |
36 | import edu.harvard.seas.pl.abcdatalog.ast.PositiveAtom;
37 | import edu.harvard.seas.pl.abcdatalog.ast.PredicateSym;
38 | import edu.harvard.seas.pl.abcdatalog.ast.Premise;
39 | import edu.harvard.seas.pl.abcdatalog.ast.Term;
40 | import edu.harvard.seas.pl.abcdatalog.ast.visitors.PremiseVisitor;
41 | import edu.harvard.seas.pl.abcdatalog.util.substitution.Substitution;
42 |
43 | /**
44 | * An annotated atom. In certain evaluation algorithms (such as semi-naive evaluation) it is helpful
45 | * to have an annotation associated with an atom.
46 | */
47 | public class AnnotatedAtom implements Premise {
48 | private final PositiveAtom atom;
49 | private final Annotation anno;
50 |
51 | public AnnotatedAtom(PositiveAtom atom, Annotation anno) {
52 | this.atom = atom;
53 | this.anno = anno;
54 | }
55 |
56 | public enum Annotation {
57 | IDB,
58 | IDB_PREV,
59 | EDB,
60 | DELTA;
61 | }
62 |
63 | public Term[] getArgs() {
64 | return atom.getArgs();
65 | }
66 |
67 | public PredicateSym getPred() {
68 | return atom.getPred();
69 | }
70 |
71 | public PositiveAtom asUnannotatedAtom() {
72 | return atom;
73 | }
74 |
75 | public Annotation getAnnotation() {
76 | return anno;
77 | }
78 |
79 | @Override
80 | public O accept(PremiseVisitor visitor, I state) {
81 | return visitor.visit(this, state);
82 | }
83 |
84 | @Override
85 | public String toString() {
86 | String a = "";
87 | switch (anno) {
88 | case IDB:
89 | a = "IDB";
90 | break;
91 | case IDB_PREV:
92 | a = "IDB_PREV";
93 | break;
94 | case EDB:
95 | a = "EDB";
96 | break;
97 | case DELTA:
98 | a = "DELTA";
99 | break;
100 | default:
101 | assert false;
102 | }
103 | return atom + "<" + a + ">";
104 | }
105 |
106 | @Override
107 | public Premise applySubst(Substitution subst) {
108 | return new AnnotatedAtom(atom.applySubst(subst), anno);
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/src/main/java/edu/harvard/seas/pl/abcdatalog/engine/bottomup/BottomUpEngineFrame.java:
--------------------------------------------------------------------------------
1 | package edu.harvard.seas.pl.abcdatalog.engine.bottomup;
2 |
3 | /*-
4 | * #%L
5 | * AbcDatalog
6 | * %%
7 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
8 | * %%
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | *
12 | * 1. Redistributions of source code must retain the above copyright notice, this
13 | * list of conditions and the following disclaimer.
14 | *
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | *
19 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software without
21 | * specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
32 | * OF THE POSSIBILITY OF SUCH DAMAGE.
33 | * #L%
34 | */
35 |
36 | import edu.harvard.seas.pl.abcdatalog.ast.Clause;
37 | import edu.harvard.seas.pl.abcdatalog.ast.PositiveAtom;
38 | import edu.harvard.seas.pl.abcdatalog.ast.validation.DatalogValidationException;
39 | import edu.harvard.seas.pl.abcdatalog.engine.DatalogEngine;
40 | import edu.harvard.seas.pl.abcdatalog.util.datastructures.IndexableFactCollection;
41 | import java.util.HashSet;
42 | import java.util.Set;
43 |
44 | /** A framework for a bottom-up Datalog engine. */
45 | public class BottomUpEngineFrame implements DatalogEngine {
46 | /** The evaluation manager for this engine. */
47 | protected final E manager;
48 |
49 | /** The set of facts that can be derived from the current program. */
50 | private volatile IndexableFactCollection facts;
51 |
52 | /** Has the engine been initialized? */
53 | private volatile boolean isInitialized = false;
54 |
55 | /**
56 | * Constructs a bottom-up engine with the provided evaluation manager.
57 | *
58 | * @param manager the manager
59 | */
60 | public BottomUpEngineFrame(E manager) {
61 | this.manager = manager;
62 | }
63 |
64 | @Override
65 | public synchronized void init(Set program) throws DatalogValidationException {
66 | if (this.isInitialized) {
67 | throw new IllegalStateException("Cannot initialize an engine more than once.");
68 | }
69 |
70 | this.manager.initialize(program);
71 | this.facts = this.manager.eval();
72 | this.isInitialized = true;
73 | }
74 |
75 | @Override
76 | public Set query(PositiveAtom q) {
77 | if (!this.isInitialized) {
78 | throw new IllegalStateException("Engine must be initialized before it can be queried.");
79 | }
80 |
81 | Set r = new HashSet<>();
82 | for (PositiveAtom a : this.facts.indexInto(q)) {
83 | if (q.unify(a) != null) {
84 | r.add(a);
85 | }
86 | }
87 | return r;
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/src/main/java/edu/harvard/seas/pl/abcdatalog/engine/bottomup/BottomUpEngineFrameWithProvenance.java:
--------------------------------------------------------------------------------
1 | package edu.harvard.seas.pl.abcdatalog.engine.bottomup;
2 |
3 | /*-
4 | * #%L
5 | * AbcDatalog
6 | * %%
7 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
8 | * %%
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | *
12 | * 1. Redistributions of source code must retain the above copyright notice, this
13 | * list of conditions and the following disclaimer.
14 | *
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | *
19 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software without
21 | * specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
32 | * OF THE POSSIBILITY OF SUCH DAMAGE.
33 | * #L%
34 | */
35 |
36 | import edu.harvard.seas.pl.abcdatalog.ast.Clause;
37 | import edu.harvard.seas.pl.abcdatalog.ast.PositiveAtom;
38 | import edu.harvard.seas.pl.abcdatalog.engine.DatalogEngineWithProvenance;
39 |
40 | public class BottomUpEngineFrameWithProvenance
41 | extends BottomUpEngineFrame implements DatalogEngineWithProvenance {
42 |
43 | public BottomUpEngineFrameWithProvenance(EvalManagerWithProvenance manager) {
44 | super(manager);
45 | }
46 |
47 | @Override
48 | public Clause getJustification(PositiveAtom fact) {
49 | return manager.getJustification(fact);
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/edu/harvard/seas/pl/abcdatalog/engine/bottomup/EvalManager.java:
--------------------------------------------------------------------------------
1 | package edu.harvard.seas.pl.abcdatalog.engine.bottomup;
2 |
3 | /*-
4 | * #%L
5 | * AbcDatalog
6 | * %%
7 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
8 | * %%
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | *
12 | * 1. Redistributions of source code must retain the above copyright notice, this
13 | * list of conditions and the following disclaimer.
14 | *
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | *
19 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software without
21 | * specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
32 | * OF THE POSSIBILITY OF SUCH DAMAGE.
33 | * #L%
34 | */
35 |
36 | import edu.harvard.seas.pl.abcdatalog.ast.Clause;
37 | import edu.harvard.seas.pl.abcdatalog.ast.validation.DatalogValidationException;
38 | import edu.harvard.seas.pl.abcdatalog.util.datastructures.IndexableFactCollection;
39 | import java.util.Set;
40 |
41 | /** The saturating evaluation manager for a bottom-up Datalog evaluation engine. */
42 | public interface EvalManager {
43 | /**
44 | * Initialize this manager with a program.
45 | *
46 | * @param program the program
47 | * @throws DatalogValidationException if the program is invalid
48 | */
49 | void initialize(Set program) throws DatalogValidationException;
50 |
51 | /**
52 | * Saturate all facts derivable from the program with which this manager has been initialized.
53 | *
54 | * @param program the program
55 | * @return the facts
56 | */
57 | IndexableFactCollection eval();
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/edu/harvard/seas/pl/abcdatalog/engine/bottomup/EvalManagerWithProvenance.java:
--------------------------------------------------------------------------------
1 | package edu.harvard.seas.pl.abcdatalog.engine.bottomup;
2 |
3 | /*-
4 | * #%L
5 | * AbcDatalog
6 | * %%
7 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
8 | * %%
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | *
12 | * 1. Redistributions of source code must retain the above copyright notice, this
13 | * list of conditions and the following disclaimer.
14 | *
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | *
19 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software without
21 | * specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
32 | * OF THE POSSIBILITY OF SUCH DAMAGE.
33 | * #L%
34 | */
35 |
36 | import edu.harvard.seas.pl.abcdatalog.ast.Clause;
37 | import edu.harvard.seas.pl.abcdatalog.ast.PositiveAtom;
38 |
39 | public interface EvalManagerWithProvenance extends EvalManager {
40 |
41 | /**
42 | * Return the last rule used in the justification of the given atom. The returned rule should be
43 | * ground (variable-free). Return null if the given atom is not a fact or was not derived.
44 | *
45 | * @param fact the fact
46 | * @return the last rule used to justify that fact
47 | */
48 | Clause getJustification(PositiveAtom fact);
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/edu/harvard/seas/pl/abcdatalog/engine/bottomup/concurrent/ConcurrentBottomUpEngine.java:
--------------------------------------------------------------------------------
1 | package edu.harvard.seas.pl.abcdatalog.engine.bottomup.concurrent;
2 |
3 | /*-
4 | * #%L
5 | * AbcDatalog
6 | * %%
7 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
8 | * %%
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | *
12 | * 1. Redistributions of source code must retain the above copyright notice, this
13 | * list of conditions and the following disclaimer.
14 | *
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | *
19 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software without
21 | * specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
32 | * OF THE POSSIBILITY OF SUCH DAMAGE.
33 | * #L%
34 | */
35 |
36 | import edu.harvard.seas.pl.abcdatalog.engine.bottomup.BottomUpEngineFrame;
37 | import edu.harvard.seas.pl.abcdatalog.engine.bottomup.EvalManager;
38 |
39 | /**
40 | * A concurrent bottom-up Datalog engine that employs a saturation algorithm similar to semi-naive
41 | * evaluation. It supports explicit unification.
42 | */
43 | public class ConcurrentBottomUpEngine extends BottomUpEngineFrame {
44 |
45 | public ConcurrentBottomUpEngine() {
46 | super(new BottomUpEvalManager());
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/edu/harvard/seas/pl/abcdatalog/engine/bottomup/concurrent/ConcurrentStratifiedNegationBottomUpEngine.java:
--------------------------------------------------------------------------------
1 | package edu.harvard.seas.pl.abcdatalog.engine.bottomup.concurrent;
2 |
3 | /*-
4 | * #%L
5 | * AbcDatalog
6 | * %%
7 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
8 | * %%
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | *
12 | * 1. Redistributions of source code must retain the above copyright notice, this
13 | * list of conditions and the following disclaimer.
14 | *
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | *
19 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software without
21 | * specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
32 | * OF THE POSSIBILITY OF SUCH DAMAGE.
33 | * #L%
34 | */
35 |
36 | import edu.harvard.seas.pl.abcdatalog.engine.bottomup.BottomUpEngineFrame;
37 | import edu.harvard.seas.pl.abcdatalog.engine.bottomup.EvalManager;
38 |
39 | /**
40 | * This class implements an experimental multi-threaded Datalog evaluation algorithm that supports
41 | * explicit unification and stratified negation.
42 | */
43 | public class ConcurrentStratifiedNegationBottomUpEngine extends BottomUpEngineFrame {
44 |
45 | public ConcurrentStratifiedNegationBottomUpEngine() {
46 | super(new StratifiedNegationEvalManager());
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/edu/harvard/seas/pl/abcdatalog/engine/bottomup/concurrent/package-info.java:
--------------------------------------------------------------------------------
1 | /** This package contains multi-threaded bottom-up Datalog evaluation engines. */
2 | package edu.harvard.seas.pl.abcdatalog.engine.bottomup.concurrent;
3 |
4 | /*-
5 | * #%L
6 | * AbcDatalog
7 | * %%
8 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
9 | * %%
10 | * Redistribution and use in source and binary forms, with or without modification,
11 | * are permitted provided that the following conditions are met:
12 | *
13 | * 1. Redistributions of source code must retain the above copyright notice, this
14 | * list of conditions and the following disclaimer.
15 | *
16 | * 2. Redistributions in binary form must reproduce the above copyright notice,
17 | * this list of conditions and the following disclaimer in the documentation
18 | * and/or other materials provided with the distribution.
19 | *
20 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
21 | * may be used to endorse or promote products derived from this software without
22 | * specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
28 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
33 | * OF THE POSSIBILITY OF SUCH DAMAGE.
34 | * #L%
35 | */
36 |
--------------------------------------------------------------------------------
/src/main/java/edu/harvard/seas/pl/abcdatalog/engine/bottomup/package-info.java:
--------------------------------------------------------------------------------
1 | /** This package contains classes and interfaces that are used in all of the bottom-up engines. */
2 | package edu.harvard.seas.pl.abcdatalog.engine.bottomup;
3 |
4 | /*-
5 | * #%L
6 | * AbcDatalog
7 | * %%
8 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
9 | * %%
10 | * Redistribution and use in source and binary forms, with or without modification,
11 | * are permitted provided that the following conditions are met:
12 | *
13 | * 1. Redistributions of source code must retain the above copyright notice, this
14 | * list of conditions and the following disclaimer.
15 | *
16 | * 2. Redistributions in binary form must reproduce the above copyright notice,
17 | * this list of conditions and the following disclaimer in the documentation
18 | * and/or other materials provided with the distribution.
19 | *
20 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
21 | * may be used to endorse or promote products derived from this software without
22 | * specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
28 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
33 | * OF THE POSSIBILITY OF SUCH DAMAGE.
34 | * #L%
35 | */
36 |
--------------------------------------------------------------------------------
/src/main/java/edu/harvard/seas/pl/abcdatalog/engine/bottomup/sequential/SemiNaiveEngine.java:
--------------------------------------------------------------------------------
1 | package edu.harvard.seas.pl.abcdatalog.engine.bottomup.sequential;
2 |
3 | /*-
4 | * #%L
5 | * AbcDatalog
6 | * %%
7 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
8 | * %%
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | *
12 | * 1. Redistributions of source code must retain the above copyright notice, this
13 | * list of conditions and the following disclaimer.
14 | *
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | *
19 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software without
21 | * specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
32 | * OF THE POSSIBILITY OF SUCH DAMAGE.
33 | * #L%
34 | */
35 |
36 | import edu.harvard.seas.pl.abcdatalog.ast.Clause;
37 | import edu.harvard.seas.pl.abcdatalog.ast.PositiveAtom;
38 | import edu.harvard.seas.pl.abcdatalog.ast.Premise;
39 | import edu.harvard.seas.pl.abcdatalog.engine.DatalogEngine;
40 | import edu.harvard.seas.pl.abcdatalog.engine.DatalogEngineWithProvenance;
41 | import edu.harvard.seas.pl.abcdatalog.engine.bottomup.BottomUpEngineFrameWithProvenance;
42 | import edu.harvard.seas.pl.abcdatalog.parser.DatalogParser;
43 | import edu.harvard.seas.pl.abcdatalog.parser.DatalogTokenizer;
44 | import java.io.Reader;
45 | import java.io.StringReader;
46 | import java.util.Set;
47 |
48 | /**
49 | * A Datalog engine that implements the classic semi-naive bottom-up evaluation algorithm. It
50 | * supports explicit unification and stratified negation.
51 | */
52 | public class SemiNaiveEngine extends BottomUpEngineFrameWithProvenance {
53 |
54 | public static DatalogEngine newEngine() {
55 | return new SemiNaiveEngine(false);
56 | }
57 |
58 | public static DatalogEngineWithProvenance newEngineWithProvenance() {
59 | return new SemiNaiveEngine(true);
60 | }
61 |
62 | public SemiNaiveEngine(boolean collectProv) {
63 | super(new SemiNaiveEvalManager(collectProv));
64 | }
65 |
66 | public static void main(String[] args) throws Exception {
67 | String[] lines = {
68 | "edge(a, b).",
69 | "edge(b, c).",
70 | "edge(c, d).",
71 | "edge(d, c).",
72 | "tc(X, Y) :- edge(X, Y).",
73 | "tc(X, Y) :- tc(X, Z), tc(Z, Y)."
74 | };
75 | StringBuilder sb = new StringBuilder();
76 | for (String line : lines) {
77 | sb.append(line);
78 | }
79 | Reader r = new StringReader(sb.toString());
80 | DatalogTokenizer t = new DatalogTokenizer(r);
81 | Set prog = DatalogParser.parseProgram(t);
82 | DatalogEngineWithProvenance e = SemiNaiveEngine.newEngineWithProvenance();
83 | e.init(prog);
84 | t = new DatalogTokenizer(new StringReader("tc(c, c)?"));
85 | PositiveAtom q = DatalogParser.parseQuery(t);
86 | Clause lastCl = e.getJustification(q);
87 | System.out.println(lastCl);
88 | for (Premise p : lastCl.getBody()) {
89 | if (p instanceof PositiveAtom) {
90 | Clause secondLastCl = e.getJustification((PositiveAtom) p);
91 | System.out.println(secondLastCl);
92 | for (Premise p2 : secondLastCl.getBody()) {
93 | System.out.println(e.getJustification((PositiveAtom) p2));
94 | }
95 | }
96 | }
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/src/main/java/edu/harvard/seas/pl/abcdatalog/engine/bottomup/sequential/package-info.java:
--------------------------------------------------------------------------------
1 | /** This package contains single-threaded bottom-up Datalog evaluation engines. */
2 | package edu.harvard.seas.pl.abcdatalog.engine.bottomup.sequential;
3 |
4 | /*-
5 | * #%L
6 | * AbcDatalog
7 | * %%
8 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
9 | * %%
10 | * Redistribution and use in source and binary forms, with or without modification,
11 | * are permitted provided that the following conditions are met:
12 | *
13 | * 1. Redistributions of source code must retain the above copyright notice, this
14 | * list of conditions and the following disclaimer.
15 | *
16 | * 2. Redistributions in binary form must reproduce the above copyright notice,
17 | * this list of conditions and the following disclaimer in the documentation
18 | * and/or other materials provided with the distribution.
19 | *
20 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
21 | * may be used to endorse or promote products derived from this software without
22 | * specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
28 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
33 | * OF THE POSSIBILITY OF SUCH DAMAGE.
34 | * #L%
35 | */
36 |
--------------------------------------------------------------------------------
/src/main/java/edu/harvard/seas/pl/abcdatalog/engine/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This package contains the standard interface for a Datalog engine (see {@link
3 | * edu.harvard.seas.pl.abcdatalog.executor.DatalogExecutor} for an alternative interface).
4 | */
5 | package edu.harvard.seas.pl.abcdatalog.engine;
6 |
7 | /*-
8 | * #%L
9 | * AbcDatalog
10 | * %%
11 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
12 | * %%
13 | * Redistribution and use in source and binary forms, with or without modification,
14 | * are permitted provided that the following conditions are met:
15 | *
16 | * 1. Redistributions of source code must retain the above copyright notice, this
17 | * list of conditions and the following disclaimer.
18 | *
19 | * 2. Redistributions in binary form must reproduce the above copyright notice,
20 | * this list of conditions and the following disclaimer in the documentation
21 | * and/or other materials provided with the distribution.
22 | *
23 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
24 | * may be used to endorse or promote products derived from this software without
25 | * specific prior written permission.
26 | *
27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
28 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
29 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
30 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
31 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
32 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
35 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
36 | * OF THE POSSIBILITY OF SUCH DAMAGE.
37 | * #L%
38 | */
39 |
--------------------------------------------------------------------------------
/src/main/java/edu/harvard/seas/pl/abcdatalog/engine/topdown/AdornedAtom.java:
--------------------------------------------------------------------------------
1 | package edu.harvard.seas.pl.abcdatalog.engine.topdown;
2 |
3 | /*-
4 | * #%L
5 | * AbcDatalog
6 | * %%
7 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
8 | * %%
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | *
12 | * 1. Redistributions of source code must retain the above copyright notice, this
13 | * list of conditions and the following disclaimer.
14 | *
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | *
19 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software without
21 | * specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
32 | * OF THE POSSIBILITY OF SUCH DAMAGE.
33 | * #L%
34 | */
35 |
36 | import edu.harvard.seas.pl.abcdatalog.ast.Term;
37 |
38 | /** An adorned atom (i.e., an atom where every argument is marked as either bound or free). */
39 | public class AdornedAtom {
40 | private final AdornedPredicateSym pred;
41 | private final Term[] args;
42 |
43 | /**
44 | * Constructs an adorned atom with the given predicate symbol and arguments.
45 | *
46 | * @param pred adorned predicate symbol
47 | * @param args arguments
48 | */
49 | public AdornedAtom(AdornedPredicateSym pred, Term[] args) {
50 | this.pred = pred;
51 | this.args = args;
52 | }
53 |
54 | @Override
55 | public String toString() {
56 | StringBuilder sb = new StringBuilder();
57 | sb.append(pred);
58 | if (this.args.length > 0) {
59 | sb.append("(");
60 | for (int i = 0; i < args.length; ++i) {
61 | sb.append(args[i]);
62 | if (i < args.length - 1) {
63 | sb.append(", ");
64 | }
65 | }
66 | sb.append(")");
67 | }
68 | return sb.toString();
69 | }
70 |
71 | public AdornedPredicateSym getPred() {
72 | return pred;
73 | }
74 |
75 | public Term[] getArgs() {
76 | return args;
77 | }
78 |
79 | @Override
80 | public int hashCode() {
81 | final int prime = 31;
82 | int result = 1;
83 | result = prime * result + ((args == null) ? 0 : args.hashCode());
84 | result = prime * result + ((pred == null) ? 0 : pred.hashCode());
85 | return result;
86 | }
87 |
88 | @Override
89 | public boolean equals(Object obj) {
90 | if (this == obj) return true;
91 | if (obj == null) return false;
92 | if (getClass() != obj.getClass()) return false;
93 | AdornedAtom other = (AdornedAtom) obj;
94 | if (args == null) {
95 | if (other.args != null) return false;
96 | } else if (!args.equals(other.args)) return false;
97 | if (pred == null) {
98 | if (other.pred != null) return false;
99 | } else if (!pred.equals(other.pred)) return false;
100 | return true;
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/src/main/java/edu/harvard/seas/pl/abcdatalog/engine/topdown/QsqSupRelation.java:
--------------------------------------------------------------------------------
1 | package edu.harvard.seas.pl.abcdatalog.engine.topdown;
2 |
3 | /*-
4 | * #%L
5 | * AbcDatalog
6 | * %%
7 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
8 | * %%
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | *
12 | * 1. Redistributions of source code must retain the above copyright notice, this
13 | * list of conditions and the following disclaimer.
14 | *
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | *
19 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software without
21 | * specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
32 | * OF THE POSSIBILITY OF SUCH DAMAGE.
33 | * #L%
34 | */
35 |
36 | /**
37 | * A supplementary relation used in QSQ evaluation.
38 | *
39 | * It is modeled as a node in a linked list. The intention is that each node contains the tuples for
40 | * the supplementary relation itself, a pointer to the atom that appears after the supplementary
41 | * relation in the relevant rule, and a pointer to the next supplementary relation in the same rule.
42 | */
43 | public class QsqSupRelation extends Relation {
44 | /** Points to the next supplementary relation in the rule being evaluated. */
45 | public QsqSupRelation next;
46 |
47 | /** Points to the atom that follows this supplementary relation in the rule being evaluated. */
48 | public AdornedAtom nextAtom;
49 |
50 | /**
51 | * Constructs an empty supplementary relation with the supplied schema.
52 | *
53 | * @param schema schema of supplementary relation
54 | */
55 | public QsqSupRelation(TermSchema schema) {
56 | super(schema);
57 | nextAtom = null;
58 | next = null;
59 | }
60 |
61 | @Override
62 | public String toString() {
63 | StringBuilder sb = new StringBuilder();
64 | sb.append(super.toString());
65 | sb.append("; Next atom: ");
66 | if (nextAtom != null) {
67 | sb.append(nextAtom);
68 | }
69 | return sb.toString();
70 | }
71 |
72 | @Override
73 | public int hashCode() {
74 | final int prime = 31;
75 | int result = super.hashCode();
76 | result = prime * result + ((next == null) ? 0 : next.hashCode());
77 | result = prime * result + ((nextAtom == null) ? 0 : nextAtom.hashCode());
78 | return result;
79 | }
80 |
81 | @Override
82 | public boolean equals(Object obj) {
83 | if (this == obj) return true;
84 | if (!super.equals(obj)) return false;
85 | if (getClass() != obj.getClass()) return false;
86 | QsqSupRelation other = (QsqSupRelation) obj;
87 | if (next == null) {
88 | if (other.next != null) return false;
89 | } else if (!next.equals(other.next)) return false;
90 | if (nextAtom == null) {
91 | if (other.nextAtom != null) return false;
92 | } else if (!nextAtom.equals(other.nextAtom)) return false;
93 | return true;
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/src/main/java/edu/harvard/seas/pl/abcdatalog/engine/topdown/Tuple.java:
--------------------------------------------------------------------------------
1 | package edu.harvard.seas.pl.abcdatalog.engine.topdown;
2 |
3 | /*-
4 | * #%L
5 | * AbcDatalog
6 | * %%
7 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
8 | * %%
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | *
12 | * 1. Redistributions of source code must retain the above copyright notice, this
13 | * list of conditions and the following disclaimer.
14 | *
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | *
19 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software without
21 | * specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
32 | * OF THE POSSIBILITY OF SUCH DAMAGE.
33 | * #L%
34 | */
35 |
36 | import edu.harvard.seas.pl.abcdatalog.ast.Term;
37 | import edu.harvard.seas.pl.abcdatalog.util.substitution.Substitution;
38 | import edu.harvard.seas.pl.abcdatalog.util.substitution.UnionFindBasedUnifier;
39 | import java.util.Arrays;
40 | import java.util.List;
41 |
42 | /** A tuple of terms, i.e., an ordered list of fixed arity. */
43 | public class Tuple {
44 | /** The terms in this tuple. */
45 | public final Term[] elts;
46 |
47 | /**
48 | * Constructs a tuple from a list of terms.
49 | *
50 | * @param elts the list of terms
51 | */
52 | public Tuple(List elts) {
53 | Term[] tmp = new Term[elts.size()];
54 | this.elts = elts.toArray(tmp);
55 | }
56 |
57 | public Tuple(Term[] elts) {
58 | this.elts = elts;
59 | }
60 |
61 | /**
62 | * Returns the term at the ith position in this tuple (0-indexed).
63 | *
64 | * @param i the position
65 | * @return the term
66 | */
67 | public Term get(int i) {
68 | return this.elts[i];
69 | }
70 |
71 | /**
72 | * Returns the arity of this tuple.
73 | *
74 | * @return the arity
75 | */
76 | public int size() {
77 | return this.elts.length;
78 | }
79 |
80 | /**
81 | * Attempts to unify this tuple with another tuple.
82 | *
83 | * @param other the other tuple
84 | * @return the substitution resulting from the unification, or null if the unification fails
85 | */
86 | public Tuple unify(Tuple other) {
87 | Substitution subst = UnionFindBasedUnifier.fromTerms(this.elts, other.elts);
88 | if (subst != null) {
89 | return new Tuple(subst.apply(this.elts));
90 | }
91 | return null;
92 | }
93 |
94 | @Override
95 | public String toString() {
96 | StringBuilder sb = new StringBuilder();
97 | sb.append("<");
98 | for (int i = 0; i < this.elts.length; ++i) {
99 | sb.append(elts[i]);
100 | if (i < this.elts.length - 1) {
101 | sb.append(", ");
102 | }
103 | }
104 | sb.append(">");
105 | return sb.toString();
106 | }
107 |
108 | @Override
109 | public int hashCode() {
110 | final int prime = 31;
111 | int result = 1;
112 | result = prime * result + Arrays.hashCode(elts);
113 | return result;
114 | }
115 |
116 | @Override
117 | public boolean equals(Object obj) {
118 | if (this == obj) return true;
119 | if (obj == null) return false;
120 | if (getClass() != obj.getClass()) return false;
121 | Tuple other = (Tuple) obj;
122 | if (!Arrays.equals(elts, other.elts)) return false;
123 | return true;
124 | }
125 | }
126 |
--------------------------------------------------------------------------------
/src/main/java/edu/harvard/seas/pl/abcdatalog/engine/topdown/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This package contains implementations of standard top-down Datalog evaluation algorithms. The
3 | * implementations here should be viewed as less-trustworthy than the bottom-up implementations in
4 | * {@link edu.harvard.seas.pl.abcdatalog.engine.bottomup.sequential} and {@link
5 | * edu.harvard.seas.pl.abcdatalog.engine.bottomup.concurrent}.
6 | */
7 | package edu.harvard.seas.pl.abcdatalog.engine.topdown;
8 |
9 | /*-
10 | * #%L
11 | * AbcDatalog
12 | * %%
13 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
14 | * %%
15 | * Redistribution and use in source and binary forms, with or without modification,
16 | * are permitted provided that the following conditions are met:
17 | *
18 | * 1. Redistributions of source code must retain the above copyright notice, this
19 | * list of conditions and the following disclaimer.
20 | *
21 | * 2. Redistributions in binary form must reproduce the above copyright notice,
22 | * this list of conditions and the following disclaimer in the documentation
23 | * and/or other materials provided with the distribution.
24 | *
25 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
26 | * may be used to endorse or promote products derived from this software without
27 | * specific prior written permission.
28 | *
29 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
30 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
31 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
32 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
34 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
36 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
37 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
38 | * OF THE POSSIBILITY OF SUCH DAMAGE.
39 | * #L%
40 | */
41 |
--------------------------------------------------------------------------------
/src/main/java/edu/harvard/seas/pl/abcdatalog/executor/DatalogExecutor.java:
--------------------------------------------------------------------------------
1 | package edu.harvard.seas.pl.abcdatalog.executor;
2 |
3 | /*-
4 | * #%L
5 | * AbcDatalog
6 | * %%
7 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
8 | * %%
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | *
12 | * 1. Redistributions of source code must retain the above copyright notice, this
13 | * list of conditions and the following disclaimer.
14 | *
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | *
19 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software without
21 | * specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
32 | * OF THE POSSIBILITY OF SUCH DAMAGE.
33 | * #L%
34 | */
35 |
36 | import edu.harvard.seas.pl.abcdatalog.ast.Clause;
37 | import edu.harvard.seas.pl.abcdatalog.ast.PositiveAtom;
38 | import edu.harvard.seas.pl.abcdatalog.ast.PredicateSym;
39 | import edu.harvard.seas.pl.abcdatalog.ast.validation.DatalogValidationException;
40 | import java.util.Set;
41 |
42 | /**
43 | * A interface to an ongoing Datalog evaluation that allows for callbacks to be registered that are
44 | * invoked when relevant new facts are derived and for new EDB facts to be added in the midst of
45 | * evaluation.
46 | */
47 | public interface DatalogExecutor {
48 | /**
49 | * Initializes the Datalog engine with a program and specifies which EDB relations can be extended
50 | * (with DatalogExecutor.addFactAsynchronously()) during evaluation. This should only be called
51 | * once.
52 | *
53 | * @param program the program
54 | * @param extendibleEdbPreds the extendible EDB relations
55 | * @throws DatalogValidationException if program is invalid
56 | */
57 | void initialize(Set program, Set extendibleEdbPreds)
58 | throws DatalogValidationException;
59 |
60 | /**
61 | * Starts the Datalog evaluation.
62 | *
63 | * @throws IllegalStateException if the executor has not been initialized or the evaluation has
64 | * already been started
65 | */
66 | void start();
67 |
68 | /**
69 | * Asynchronously adds a new EDB fact to the Datalog evaluation. The EDB fact must be part of a
70 | * relation that is specified in DatalogExecutor.initialize() as being extendible. A fact is a
71 | * ground atom (i.e., an atom without any variables).
72 | *
73 | * @param edbFact the new EDB fact
74 | * @throws IllegalStateException if the executor has not been initialized
75 | * @throws IllegalArgumentException if the provided atom is not ground, or if it is not part of a
76 | * relation specified during initialization as being extendible
77 | */
78 | void addFactAsynchronously(PositiveAtom edbFact);
79 |
80 | /**
81 | * Associates a listener with a given predicate symbol, so that if any fact is derived during
82 | * evaluation with that predicate symbol, the listener will be invoked with that fact. The
83 | * listener can be executed in an arbitrary thread and should not block.
84 | *
85 | * @param p the predicate symbol
86 | * @param listener the listener
87 | * @throws IllegalStateException if the evaluation has already been started
88 | */
89 | void registerListener(PredicateSym p, DatalogListener listener);
90 |
91 | /** Shuts down the executor, which cannot be reused. */
92 | void shutdown();
93 | }
94 |
--------------------------------------------------------------------------------
/src/main/java/edu/harvard/seas/pl/abcdatalog/executor/DatalogListener.java:
--------------------------------------------------------------------------------
1 | package edu.harvard.seas.pl.abcdatalog.executor;
2 |
3 | /*-
4 | * #%L
5 | * AbcDatalog
6 | * %%
7 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
8 | * %%
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | *
12 | * 1. Redistributions of source code must retain the above copyright notice, this
13 | * list of conditions and the following disclaimer.
14 | *
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | *
19 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software without
21 | * specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
32 | * OF THE POSSIBILITY OF SUCH DAMAGE.
33 | * #L%
34 | */
35 |
36 | import edu.harvard.seas.pl.abcdatalog.ast.PositiveAtom;
37 |
38 | /** A callback that is registered with a Datalog executor and is invoked during evaluation. */
39 | public interface DatalogListener {
40 | /**
41 | * Is invoked when a relevant new fact is derived during Datalog evaluation. Note that
42 | * fact.isGround() will be true (i.e., a fact is a ground atom).
43 | *
44 | * @param fact the new fact
45 | */
46 | void newFactDerived(PositiveAtom fact);
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/edu/harvard/seas/pl/abcdatalog/executor/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This package contains classes that implement a Datalog executor, which is a Datalog engine that
3 | * runs asynchronously. New facts can be added to the engine in the midst of evaluation.
4 | */
5 | package edu.harvard.seas.pl.abcdatalog.executor;
6 |
7 | /*-
8 | * #%L
9 | * AbcDatalog
10 | * %%
11 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
12 | * %%
13 | * Redistribution and use in source and binary forms, with or without modification,
14 | * are permitted provided that the following conditions are met:
15 | *
16 | * 1. Redistributions of source code must retain the above copyright notice, this
17 | * list of conditions and the following disclaimer.
18 | *
19 | * 2. Redistributions in binary form must reproduce the above copyright notice,
20 | * this list of conditions and the following disclaimer in the documentation
21 | * and/or other materials provided with the distribution.
22 | *
23 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
24 | * may be used to endorse or promote products derived from this software without
25 | * specific prior written permission.
26 | *
27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
28 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
29 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
30 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
31 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
32 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
35 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
36 | * OF THE POSSIBILITY OF SUCH DAMAGE.
37 | * #L%
38 | */
39 |
--------------------------------------------------------------------------------
/src/main/java/edu/harvard/seas/pl/abcdatalog/gui/package-info.java:
--------------------------------------------------------------------------------
1 | /** This package contains a graphical user interface for a Datalog editor and interpreter. */
2 | package edu.harvard.seas.pl.abcdatalog.gui;
3 |
4 | /*-
5 | * #%L
6 | * AbcDatalog
7 | * %%
8 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
9 | * %%
10 | * Redistribution and use in source and binary forms, with or without modification,
11 | * are permitted provided that the following conditions are met:
12 | *
13 | * 1. Redistributions of source code must retain the above copyright notice, this
14 | * list of conditions and the following disclaimer.
15 | *
16 | * 2. Redistributions in binary form must reproduce the above copyright notice,
17 | * this list of conditions and the following disclaimer in the documentation
18 | * and/or other materials provided with the distribution.
19 | *
20 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
21 | * may be used to endorse or promote products derived from this software without
22 | * specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
28 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
33 | * OF THE POSSIBILITY OF SUCH DAMAGE.
34 | * #L%
35 | */
36 |
--------------------------------------------------------------------------------
/src/main/java/edu/harvard/seas/pl/abcdatalog/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * AbcDatalog, an implementation of Datalog that is intended to be easily extensible with new
3 | * language features and new evaluation engines.
4 | */
5 | package edu.harvard.seas.pl.abcdatalog;
6 |
7 | /*-
8 | * #%L
9 | * AbcDatalog
10 | * %%
11 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
12 | * %%
13 | * Redistribution and use in source and binary forms, with or without modification,
14 | * are permitted provided that the following conditions are met:
15 | *
16 | * 1. Redistributions of source code must retain the above copyright notice, this
17 | * list of conditions and the following disclaimer.
18 | *
19 | * 2. Redistributions in binary form must reproduce the above copyright notice,
20 | * this list of conditions and the following disclaimer in the documentation
21 | * and/or other materials provided with the distribution.
22 | *
23 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
24 | * may be used to endorse or promote products derived from this software without
25 | * specific prior written permission.
26 | *
27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
28 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
29 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
30 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
31 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
32 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
35 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
36 | * OF THE POSSIBILITY OF SUCH DAMAGE.
37 | * #L%
38 | */
39 |
--------------------------------------------------------------------------------
/src/main/java/edu/harvard/seas/pl/abcdatalog/parser/DatalogParseException.java:
--------------------------------------------------------------------------------
1 | package edu.harvard.seas.pl.abcdatalog.parser;
2 |
3 | /*-
4 | * #%L
5 | * AbcDatalog
6 | * %%
7 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
8 | * %%
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | *
12 | * 1. Redistributions of source code must retain the above copyright notice, this
13 | * list of conditions and the following disclaimer.
14 | *
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | *
19 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software without
21 | * specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
32 | * OF THE POSSIBILITY OF SUCH DAMAGE.
33 | * #L%
34 | */
35 |
36 | /** An exception signifying a parsing error. */
37 | public class DatalogParseException extends Exception {
38 | /** Constructs an exception signifying a parsing error. */
39 | public DatalogParseException() {}
40 |
41 | /**
42 | * Constructs an exception signifying a parsing error.
43 | *
44 | * @param message the error message
45 | */
46 | public DatalogParseException(String message) {
47 | super(message);
48 | }
49 |
50 | /**
51 | * Constructs an exception signifying a parsing error.
52 | *
53 | * @param cause the exception that caused this exception
54 | */
55 | public DatalogParseException(Throwable cause) {
56 | super(cause);
57 | }
58 |
59 | /**
60 | * Constructs an exception signifying a parsing error.
61 | *
62 | * @param message the error message
63 | * @param cause the exception that caused this exception
64 | */
65 | public DatalogParseException(String message, Throwable cause) {
66 | super(message, cause);
67 | }
68 |
69 | /**
70 | * Constructs an exception signifying a parsing error.
71 | *
72 | * @param message the error message
73 | * @param cause the exception that caused this exception
74 | * @param enableSuppression whether or not suppression is enabled or disabled
75 | * @param writableStackTrace whether or not the stack trace should be writable
76 | */
77 | public DatalogParseException(
78 | String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
79 | super(message, cause, enableSuppression, writableStackTrace);
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/main/java/edu/harvard/seas/pl/abcdatalog/parser/package-info.java:
--------------------------------------------------------------------------------
1 | /** This package contains classes that implement a parser for Datalog source code. */
2 | package edu.harvard.seas.pl.abcdatalog.parser;
3 |
4 | /*-
5 | * #%L
6 | * AbcDatalog
7 | * %%
8 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
9 | * %%
10 | * Redistribution and use in source and binary forms, with or without modification,
11 | * are permitted provided that the following conditions are met:
12 | *
13 | * 1. Redistributions of source code must retain the above copyright notice, this
14 | * list of conditions and the following disclaimer.
15 | *
16 | * 2. Redistributions in binary form must reproduce the above copyright notice,
17 | * this list of conditions and the following disclaimer in the documentation
18 | * and/or other materials provided with the distribution.
19 | *
20 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
21 | * may be used to endorse or promote products derived from this software without
22 | * specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
28 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
33 | * OF THE POSSIBILITY OF SUCH DAMAGE.
34 | * #L%
35 | */
36 |
--------------------------------------------------------------------------------
/src/main/java/edu/harvard/seas/pl/abcdatalog/util/Box.java:
--------------------------------------------------------------------------------
1 | package edu.harvard.seas.pl.abcdatalog.util;
2 |
3 | /*-
4 | * #%L
5 | * AbcDatalog
6 | * %%
7 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
8 | * %%
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | *
12 | * 1. Redistributions of source code must retain the above copyright notice, this
13 | * list of conditions and the following disclaimer.
14 | *
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | *
19 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software without
21 | * specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
32 | * OF THE POSSIBILITY OF SUCH DAMAGE.
33 | * #L%
34 | */
35 |
36 | public class Box {
37 | public T value;
38 |
39 | public Box() {}
40 | ;
41 |
42 | public Box(T value) {
43 | this.value = value;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/edu/harvard/seas/pl/abcdatalog/util/Utilities.java:
--------------------------------------------------------------------------------
1 | package edu.harvard.seas.pl.abcdatalog.util;
2 |
3 | /*-
4 | * #%L
5 | * AbcDatalog
6 | * %%
7 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
8 | * %%
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | *
12 | * 1. Redistributions of source code must retain the above copyright notice, this
13 | * list of conditions and the following disclaimer.
14 | *
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | *
19 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software without
21 | * specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
32 | * OF THE POSSIBILITY OF SUCH DAMAGE.
33 | * #L%
34 | */
35 |
36 | import java.util.Collections;
37 | import java.util.LinkedHashSet;
38 | import java.util.Map;
39 | import java.util.Set;
40 | import java.util.concurrent.ConcurrentHashMap;
41 | import java.util.concurrent.ConcurrentMap;
42 |
43 | /** "Static" class containing utility methods. */
44 | public final class Utilities {
45 |
46 | private Utilities() {
47 | // Cannot be instantiated.
48 | }
49 |
50 | public static final int concurrency = Runtime.getRuntime().availableProcessors();
51 |
52 | public static Set createConcurrentSet() {
53 | return Collections.newSetFromMap(createConcurrentMap());
54 | }
55 |
56 | public static ConcurrentMap createConcurrentMap() {
57 | return new ConcurrentHashMap<>(16, 0.75f, concurrency);
58 | }
59 |
60 | /**
61 | * Returns the set in map associated with key, creating a new set if needed.
62 | *
63 | * @param map the map
64 | * @param key the key
65 | * @return the set
66 | */
67 | public static Set getSetFromMap(Map> map, K key) {
68 | Set vals = map.get(key);
69 | if (vals == null) {
70 | vals = new LinkedHashSet<>();
71 | map.put(key, vals);
72 | }
73 | return vals;
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/main/java/edu/harvard/seas/pl/abcdatalog/util/datastructures/FactIndexer.java:
--------------------------------------------------------------------------------
1 | package edu.harvard.seas.pl.abcdatalog.util.datastructures;
2 |
3 | /*-
4 | * #%L
5 | * AbcDatalog
6 | * %%
7 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
8 | * %%
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | *
12 | * 1. Redistributions of source code must retain the above copyright notice, this
13 | * list of conditions and the following disclaimer.
14 | *
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | *
19 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software without
21 | * specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
32 | * OF THE POSSIBILITY OF SUCH DAMAGE.
33 | * #L%
34 | */
35 |
36 | import edu.harvard.seas.pl.abcdatalog.ast.PositiveAtom;
37 |
38 | public interface FactIndexer extends IndexableFactCollection {
39 | /**
40 | * Adds a fact to the FactIndexer.
41 | *
42 | * @param fact a fact
43 | */
44 | public void add(PositiveAtom fact);
45 |
46 | /**
47 | * Adds some number of facts to the FactIndexer.
48 | *
49 | * @param facts some facts
50 | */
51 | public void addAll(Iterable facts);
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/edu/harvard/seas/pl/abcdatalog/util/datastructures/FactIndexerFactory.java:
--------------------------------------------------------------------------------
1 | package edu.harvard.seas.pl.abcdatalog.util.datastructures;
2 |
3 | /*-
4 | * #%L
5 | * AbcDatalog
6 | * %%
7 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
8 | * %%
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | *
12 | * 1. Redistributions of source code must retain the above copyright notice, this
13 | * list of conditions and the following disclaimer.
14 | *
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | *
19 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software without
21 | * specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
32 | * OF THE POSSIBILITY OF SUCH DAMAGE.
33 | * #L%
34 | */
35 |
36 | import edu.harvard.seas.pl.abcdatalog.ast.PositiveAtom;
37 | import edu.harvard.seas.pl.abcdatalog.util.Utilities;
38 | import java.util.Queue;
39 | import java.util.Set;
40 | import java.util.concurrent.ConcurrentLinkedQueue;
41 |
42 | /** A factory for creating some useful fact indexers. */
43 | public final class FactIndexerFactory {
44 |
45 | private FactIndexerFactory() {}
46 |
47 | /**
48 | * Creates a fact indexer that uses concurrent sets for the base container.
49 | *
50 | * @return the fact indexer
51 | */
52 | public static ConcurrentFactIndexer> createConcurrentSetFactIndexer() {
53 | return new ConcurrentFactIndexer<>(Utilities::createConcurrentSet, Set::add, Set::size);
54 | }
55 |
56 | /**
57 | * Creates a fact indexer that uses concurrent queues for the base container.
58 | *
59 | * @return the fact indexer
60 | */
61 | public static ConcurrentFactIndexer> createConcurrentQueueFactIndexer() {
62 | return new ConcurrentFactIndexer<>(ConcurrentLinkedQueue::new, Queue::add, Queue::size);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/edu/harvard/seas/pl/abcdatalog/util/datastructures/IndexableFactCollection.java:
--------------------------------------------------------------------------------
1 | package edu.harvard.seas.pl.abcdatalog.util.datastructures;
2 |
3 | /*-
4 | * #%L
5 | * AbcDatalog
6 | * %%
7 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
8 | * %%
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | *
12 | * 1. Redistributions of source code must retain the above copyright notice, this
13 | * list of conditions and the following disclaimer.
14 | *
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | *
19 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software without
21 | * specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
32 | * OF THE POSSIBILITY OF SUCH DAMAGE.
33 | * #L%
34 | */
35 |
36 | import edu.harvard.seas.pl.abcdatalog.ast.PositiveAtom;
37 | import edu.harvard.seas.pl.abcdatalog.ast.PredicateSym;
38 | import edu.harvard.seas.pl.abcdatalog.util.substitution.ConstOnlySubstitution;
39 | import java.util.Set;
40 |
41 | /**
42 | * A fixed collection of facts that only allows a basic query operation: return the atoms in the
43 | * collection that might match a given atom.
44 | */
45 | public interface IndexableFactCollection {
46 | /**
47 | * Returns the atoms in the collection that potentially "match" the provided atom. There is no
48 | * guarantee that the returned atoms can actually be unified with the provided atom.
49 | *
50 | * @param atom the atom to match
51 | * @return the matching facts
52 | */
53 | public Iterable indexInto(PositiveAtom atom);
54 |
55 | /**
56 | * Returns the atoms in the collection that potentially "match" the provided atom, after the given
57 | * substitution has been applied. There is no guarantee that the returned atoms can actually be
58 | * unified with the provided atom.
59 | *
60 | * @param atom the atom to match
61 | * @return the matching facts
62 | */
63 | public Iterable indexInto(PositiveAtom atom, ConstOnlySubstitution subst);
64 |
65 | /**
66 | * Returns the atoms in the collection with the given predicate symbol.
67 | *
68 | * @param pred the predicate symbol
69 | * @return the matching facts
70 | */
71 | public Iterable indexInto(PredicateSym pred);
72 |
73 | /**
74 | * Returns whether the collection is empty.
75 | *
76 | * @return whether the collection is empty
77 | */
78 | public boolean isEmpty();
79 |
80 | /**
81 | * Returns the set of the predicate symbols represented in this collection.
82 | *
83 | * @return the predicate symbols
84 | */
85 | Set getPreds();
86 | }
87 |
--------------------------------------------------------------------------------
/src/main/java/edu/harvard/seas/pl/abcdatalog/util/datastructures/package-info.java:
--------------------------------------------------------------------------------
1 | /** This package contains data structures for storing and indexing Datalog facts. */
2 | package edu.harvard.seas.pl.abcdatalog.util.datastructures;
3 |
4 | /*-
5 | * #%L
6 | * AbcDatalog
7 | * %%
8 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
9 | * %%
10 | * Redistribution and use in source and binary forms, with or without modification,
11 | * are permitted provided that the following conditions are met:
12 | *
13 | * 1. Redistributions of source code must retain the above copyright notice, this
14 | * list of conditions and the following disclaimer.
15 | *
16 | * 2. Redistributions in binary form must reproduce the above copyright notice,
17 | * this list of conditions and the following disclaimer in the documentation
18 | * and/or other materials provided with the distribution.
19 | *
20 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
21 | * may be used to endorse or promote products derived from this software without
22 | * specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
28 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
33 | * OF THE POSSIBILITY OF SUCH DAMAGE.
34 | * #L%
35 | */
36 |
--------------------------------------------------------------------------------
/src/main/java/edu/harvard/seas/pl/abcdatalog/util/graph/DirectedEdge.java:
--------------------------------------------------------------------------------
1 | package edu.harvard.seas.pl.abcdatalog.util.graph;
2 |
3 | /*-
4 | * #%L
5 | * AbcDatalog
6 | * %%
7 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
8 | * %%
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | *
12 | * 1. Redistributions of source code must retain the above copyright notice, this
13 | * list of conditions and the following disclaimer.
14 | *
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | *
19 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software without
21 | * specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
32 | * OF THE POSSIBILITY OF SUCH DAMAGE.
33 | * #L%
34 | */
35 |
36 | public interface DirectedEdge {
37 | public V getSource();
38 |
39 | public V getDest();
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/edu/harvard/seas/pl/abcdatalog/util/graph/package-info.java:
--------------------------------------------------------------------------------
1 | /** This package contains utility classes for graph operations. */
2 | package edu.harvard.seas.pl.abcdatalog.util.graph;
3 |
4 | /*-
5 | * #%L
6 | * AbcDatalog
7 | * %%
8 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
9 | * %%
10 | * Redistribution and use in source and binary forms, with or without modification,
11 | * are permitted provided that the following conditions are met:
12 | *
13 | * 1. Redistributions of source code must retain the above copyright notice, this
14 | * list of conditions and the following disclaimer.
15 | *
16 | * 2. Redistributions in binary form must reproduce the above copyright notice,
17 | * this list of conditions and the following disclaimer in the documentation
18 | * and/or other materials provided with the distribution.
19 | *
20 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
21 | * may be used to endorse or promote products derived from this software without
22 | * specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
28 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
33 | * OF THE POSSIBILITY OF SUCH DAMAGE.
34 | * #L%
35 | */
36 |
--------------------------------------------------------------------------------
/src/main/java/edu/harvard/seas/pl/abcdatalog/util/package-info.java:
--------------------------------------------------------------------------------
1 | /** This package contains basic utilities. */
2 | package edu.harvard.seas.pl.abcdatalog.util;
3 |
4 | /*-
5 | * #%L
6 | * AbcDatalog
7 | * %%
8 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
9 | * %%
10 | * Redistribution and use in source and binary forms, with or without modification,
11 | * are permitted provided that the following conditions are met:
12 | *
13 | * 1. Redistributions of source code must retain the above copyright notice, this
14 | * list of conditions and the following disclaimer.
15 | *
16 | * 2. Redistributions in binary form must reproduce the above copyright notice,
17 | * this list of conditions and the following disclaimer in the documentation
18 | * and/or other materials provided with the distribution.
19 | *
20 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
21 | * may be used to endorse or promote products derived from this software without
22 | * specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
28 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
33 | * OF THE POSSIBILITY OF SUCH DAMAGE.
34 | * #L%
35 | */
36 |
--------------------------------------------------------------------------------
/src/main/java/edu/harvard/seas/pl/abcdatalog/util/substitution/ConstOnlySubstitution.java:
--------------------------------------------------------------------------------
1 | package edu.harvard.seas.pl.abcdatalog.util.substitution;
2 |
3 | /*-
4 | * #%L
5 | * AbcDatalog
6 | * %%
7 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
8 | * %%
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | *
12 | * 1. Redistributions of source code must retain the above copyright notice, this
13 | * list of conditions and the following disclaimer.
14 | *
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | *
19 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software without
21 | * specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
32 | * OF THE POSSIBILITY OF SUCH DAMAGE.
33 | * #L%
34 | */
35 |
36 | import edu.harvard.seas.pl.abcdatalog.ast.Constant;
37 | import edu.harvard.seas.pl.abcdatalog.ast.Variable;
38 |
39 | /**
40 | * A mapping from variables to constants. This is a restriction of a more general substitution,
41 | * which is from variables to terms.
42 | */
43 | public interface ConstOnlySubstitution extends Substitution {
44 | /**
45 | * Retrieves the mapping of a variable.
46 | *
47 | * @param x the variable
48 | * @return the constant that the variable is bound to, or null if the variable is not in the
49 | * substitution
50 | */
51 | @Override
52 | Constant get(Variable x);
53 |
54 | /**
55 | * Attempts to add a mapping to the substitution. Returns true if the mapping was made
56 | * successfully (i.e., if the variable was not already mapped to another constant).
57 | *
58 | * @param x the variable
59 | * @param c the constant
60 | * @return whether the mapping was successfully added
61 | */
62 | boolean add(Variable x, Constant c);
63 | }
64 |
--------------------------------------------------------------------------------
/src/main/java/edu/harvard/seas/pl/abcdatalog/util/substitution/Substitution.java:
--------------------------------------------------------------------------------
1 | package edu.harvard.seas.pl.abcdatalog.util.substitution;
2 |
3 | /*-
4 | * #%L
5 | * AbcDatalog
6 | * %%
7 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
8 | * %%
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | *
12 | * 1. Redistributions of source code must retain the above copyright notice, this
13 | * list of conditions and the following disclaimer.
14 | *
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | *
19 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software without
21 | * specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
32 | * OF THE POSSIBILITY OF SUCH DAMAGE.
33 | * #L%
34 | */
35 |
36 | import edu.harvard.seas.pl.abcdatalog.ast.Term;
37 | import edu.harvard.seas.pl.abcdatalog.ast.Variable;
38 |
39 | /** A mapping from variables to terms. */
40 | public interface Substitution {
41 | /**
42 | * Apply this substitution to a list of terms, creating a new list.
43 | *
44 | * @param original the original list
45 | * @return the new list
46 | */
47 | Term[] apply(Term[] original);
48 |
49 | /**
50 | * Retrieves the mapping of a variable.
51 | *
52 | * @param x the variable
53 | * @return the term that the variable is bound to, or null if the variable is not in the
54 | * substitution
55 | */
56 | Term get(Variable x);
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/edu/harvard/seas/pl/abcdatalog/util/substitution/SubstitutionUtils.java:
--------------------------------------------------------------------------------
1 | package edu.harvard.seas.pl.abcdatalog.util.substitution;
2 |
3 | /*-
4 | * #%L
5 | * AbcDatalog
6 | * %%
7 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
8 | * %%
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | *
12 | * 1. Redistributions of source code must retain the above copyright notice, this
13 | * list of conditions and the following disclaimer.
14 | *
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | *
19 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software without
21 | * specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
32 | * OF THE POSSIBILITY OF SUCH DAMAGE.
33 | * #L%
34 | */
35 |
36 | import edu.harvard.seas.pl.abcdatalog.ast.Clause;
37 | import edu.harvard.seas.pl.abcdatalog.ast.Head;
38 | import edu.harvard.seas.pl.abcdatalog.ast.PositiveAtom;
39 | import edu.harvard.seas.pl.abcdatalog.ast.Premise;
40 | import java.util.ArrayList;
41 | import java.util.Collection;
42 | import java.util.List;
43 |
44 | public final class SubstitutionUtils {
45 |
46 | private SubstitutionUtils() {
47 | throw new AssertionError("impossible");
48 | }
49 |
50 | /**
51 | * Apply a substitution to the given positive atoms, adding the resulting atoms to the provided
52 | * collection (in order).
53 | *
54 | * @param subst the substitution
55 | * @param atoms the atoms
56 | * @param acc the collection to add the atoms to
57 | */
58 | public static void applyToPositiveAtoms(
59 | Substitution subst, Iterable atoms, Collection acc) {
60 | for (PositiveAtom atom : atoms) {
61 | acc.add(atom.applySubst(subst));
62 | }
63 | }
64 |
65 | /**
66 | * Apply a substitution to the given positive atoms, returning a list of the resulting atoms (in
67 | * order).
68 | *
69 | * @param subst the substitution
70 | * @param atoms the atoms
71 | * @return a list of the atoms that result from applying the substitution
72 | */
73 | public static List applyToPositiveAtoms(
74 | Substitution subst, Iterable atoms) {
75 | List ret = new ArrayList<>();
76 | applyToPositiveAtoms(subst, atoms, ret);
77 | return ret;
78 | }
79 |
80 | public static Clause applyToClause(Substitution subst, Clause cl) {
81 | Head newHead = cl.getHead().applySubst(subst);
82 | List newBody = new ArrayList<>();
83 | for (Premise p : cl.getBody()) {
84 | newBody.add(p.applySubst(subst));
85 | }
86 | return new Clause(newHead, newBody);
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/src/main/java/edu/harvard/seas/pl/abcdatalog/util/substitution/TermUnifier.java:
--------------------------------------------------------------------------------
1 | package edu.harvard.seas.pl.abcdatalog.util.substitution;
2 |
3 | /*-
4 | * #%L
5 | * AbcDatalog
6 | * %%
7 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
8 | * %%
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | *
12 | * 1. Redistributions of source code must retain the above copyright notice, this
13 | * list of conditions and the following disclaimer.
14 | *
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | *
19 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software without
21 | * specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
32 | * OF THE POSSIBILITY OF SUCH DAMAGE.
33 | * #L%
34 | */
35 |
36 | import edu.harvard.seas.pl.abcdatalog.ast.Term;
37 | import edu.harvard.seas.pl.abcdatalog.ast.Variable;
38 |
39 | /**
40 | * A substitution that allows a variable to be mapped to (i.e., unified with) multiple terms, as
41 | * long as no two of those terms are constants.
42 | */
43 | public interface TermUnifier extends Substitution {
44 | /**
45 | * Attempts to unify a variable with a term. Returns a boolean representing whether the
46 | * unification was successful. Unification fails if it would lead to a variable being unified with
47 | * two distinct constants.
48 | *
49 | * @param u the variable
50 | * @param v the term
51 | * @return whether the unification was successful
52 | */
53 | public boolean unify(Variable u, Term v);
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/edu/harvard/seas/pl/abcdatalog/util/substitution/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This package contains classes that represents substitutions (i.e., mappings from variables to
3 | * terms).
4 | */
5 | package edu.harvard.seas.pl.abcdatalog.util.substitution;
6 |
7 | /*-
8 | * #%L
9 | * AbcDatalog
10 | * %%
11 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
12 | * %%
13 | * Redistribution and use in source and binary forms, with or without modification,
14 | * are permitted provided that the following conditions are met:
15 | *
16 | * 1. Redistributions of source code must retain the above copyright notice, this
17 | * list of conditions and the following disclaimer.
18 | *
19 | * 2. Redistributions in binary form must reproduce the above copyright notice,
20 | * this list of conditions and the following disclaimer in the documentation
21 | * and/or other materials provided with the distribution.
22 | *
23 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
24 | * may be used to endorse or promote products derived from this software without
25 | * specific prior written permission.
26 | *
27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
28 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
29 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
30 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
31 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
32 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
35 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
36 | * OF THE POSSIBILITY OF SUCH DAMAGE.
37 | * #L%
38 | */
39 |
--------------------------------------------------------------------------------
/src/test/java/edu/harvard/seas/pl/abcdatalog/engine/ConcurrentBottomUpEngineTest.java:
--------------------------------------------------------------------------------
1 | package edu.harvard.seas.pl.abcdatalog.engine;
2 |
3 | /*-
4 | * #%L
5 | * AbcDatalog
6 | * %%
7 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
8 | * %%
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | *
12 | * 1. Redistributions of source code must retain the above copyright notice, this
13 | * list of conditions and the following disclaimer.
14 | *
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | *
19 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software without
21 | * specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
32 | * OF THE POSSIBILITY OF SUCH DAMAGE.
33 | * #L%
34 | */
35 |
36 | import edu.harvard.seas.pl.abcdatalog.engine.bottomup.concurrent.ConcurrentBottomUpEngine;
37 | import org.junit.runner.RunWith;
38 | import org.junit.runners.Suite;
39 |
40 | @RunWith(Suite.class)
41 | @Suite.SuiteClasses({
42 | ConcurrentBottomUpEngineTest.MyCoreTests.class,
43 | ConcurrentBottomUpEngineTest.MyUnificationTests.class,
44 | ConcurrentBottomUpEngineTest.MyConjunctiveQueryTests.class
45 | })
46 | public class ConcurrentBottomUpEngineTest {
47 | public static class MyCoreTests extends CoreTests {
48 |
49 | public MyCoreTests() {
50 | super(ConcurrentBottomUpEngine::new);
51 | }
52 | }
53 |
54 | public static class MyUnificationTests extends ExplicitUnificationTests {
55 |
56 | public MyUnificationTests() {
57 | super(ConcurrentBottomUpEngine::new);
58 | }
59 | }
60 |
61 | public static class MyConjunctiveQueryTests extends ConjunctiveQueryTests {
62 |
63 | public MyConjunctiveQueryTests() {
64 | super(ConcurrentBottomUpEngine::new);
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/test/java/edu/harvard/seas/pl/abcdatalog/engine/ConcurrentChunkedBottomUpEngineTest.java:
--------------------------------------------------------------------------------
1 | package edu.harvard.seas.pl.abcdatalog.engine;
2 |
3 | /*-
4 | * #%L
5 | * AbcDatalog
6 | * %%
7 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
8 | * %%
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | *
12 | * 1. Redistributions of source code must retain the above copyright notice, this
13 | * list of conditions and the following disclaimer.
14 | *
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | *
19 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software without
21 | * specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
32 | * OF THE POSSIBILITY OF SUCH DAMAGE.
33 | * #L%
34 | */
35 |
36 | import edu.harvard.seas.pl.abcdatalog.engine.bottomup.concurrent.ConcurrentChunkedBottomUpEngine;
37 | import org.junit.runner.RunWith;
38 | import org.junit.runners.Suite;
39 |
40 | @RunWith(Suite.class)
41 | @Suite.SuiteClasses({
42 | ConcurrentChunkedBottomUpEngineTest.MyCoreTests.class,
43 | ConcurrentChunkedBottomUpEngineTest.MyUnificationTests.class,
44 | })
45 | public class ConcurrentChunkedBottomUpEngineTest {
46 |
47 | public static class MyCoreTests extends CoreTests {
48 |
49 | public MyCoreTests() {
50 | super(() -> new ConcurrentChunkedBottomUpEngine(4));
51 | }
52 | }
53 |
54 | public static class MyUnificationTests extends ExplicitUnificationTests {
55 |
56 | public MyUnificationTests() {
57 | super(() -> new ConcurrentChunkedBottomUpEngine(4));
58 | }
59 | }
60 |
61 | public static class MyConjunctiveQueryTests extends ConjunctiveQueryTests {
62 |
63 | public MyConjunctiveQueryTests() {
64 | super(() -> new ConcurrentChunkedBottomUpEngine(4));
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/test/java/edu/harvard/seas/pl/abcdatalog/engine/ConcurrentStratifiedNegationBottomUpEngineTest.java:
--------------------------------------------------------------------------------
1 | package edu.harvard.seas.pl.abcdatalog.engine;
2 |
3 | /*-
4 | * #%L
5 | * AbcDatalog
6 | * %%
7 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
8 | * %%
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | *
12 | * 1. Redistributions of source code must retain the above copyright notice, this
13 | * list of conditions and the following disclaimer.
14 | *
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | *
19 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software without
21 | * specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
32 | * OF THE POSSIBILITY OF SUCH DAMAGE.
33 | * #L%
34 | */
35 |
36 | import edu.harvard.seas.pl.abcdatalog.engine.bottomup.concurrent.ConcurrentStratifiedNegationBottomUpEngine;
37 | import org.junit.runner.RunWith;
38 | import org.junit.runners.Suite;
39 |
40 | @RunWith(Suite.class)
41 | @Suite.SuiteClasses({
42 | ConcurrentStratifiedNegationBottomUpEngineTest.MyCoreTests.class,
43 | ConcurrentStratifiedNegationBottomUpEngineTest.MyUnificationTests.class,
44 | ConcurrentStratifiedNegationBottomUpEngineTest.MyNegationTests.class
45 | })
46 | public class ConcurrentStratifiedNegationBottomUpEngineTest {
47 | public static class MyCoreTests extends CoreTests {
48 |
49 | public MyCoreTests() {
50 | super(ConcurrentStratifiedNegationBottomUpEngine::new);
51 | }
52 | }
53 |
54 | public static class MyUnificationTests extends ExplicitUnificationTests {
55 |
56 | public MyUnificationTests() {
57 | super(ConcurrentStratifiedNegationBottomUpEngine::new);
58 | }
59 | }
60 |
61 | public static class MyNegationTests extends StratifiedNegationTests {
62 |
63 | public MyNegationTests() {
64 | super(ConcurrentStratifiedNegationBottomUpEngine::new);
65 | }
66 | }
67 |
68 | public static class MyConjunctiveQueryTests extends ConjunctiveQueryTests {
69 |
70 | public MyConjunctiveQueryTests() {
71 | super(ConcurrentStratifiedNegationBottomUpEngine::new);
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/test/java/edu/harvard/seas/pl/abcdatalog/engine/IterativeQsqEngineTest.java:
--------------------------------------------------------------------------------
1 | package edu.harvard.seas.pl.abcdatalog.engine;
2 |
3 | /*-
4 | * #%L
5 | * AbcDatalog
6 | * %%
7 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
8 | * %%
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | *
12 | * 1. Redistributions of source code must retain the above copyright notice, this
13 | * list of conditions and the following disclaimer.
14 | *
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | *
19 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software without
21 | * specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
32 | * OF THE POSSIBILITY OF SUCH DAMAGE.
33 | * #L%
34 | */
35 |
36 | import edu.harvard.seas.pl.abcdatalog.engine.topdown.IterativeQsqEngine;
37 | import org.junit.runner.RunWith;
38 | import org.junit.runners.Suite;
39 |
40 | @RunWith(Suite.class)
41 | @Suite.SuiteClasses({
42 | IterativeQsqEngineTest.MyCoreTests.class,
43 | IterativeQsqEngineTest.MyConjunctiveQueryTests.class
44 | })
45 | public class IterativeQsqEngineTest {
46 | public static class MyCoreTests extends CoreTests {
47 |
48 | public MyCoreTests() {
49 | super(IterativeQsqEngine::new);
50 | }
51 | }
52 |
53 | public static class MyConjunctiveQueryTests extends ConjunctiveQueryTests {
54 |
55 | public MyConjunctiveQueryTests() {
56 | super(IterativeQsqEngine::new);
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/test/java/edu/harvard/seas/pl/abcdatalog/engine/MstEngineTest.java:
--------------------------------------------------------------------------------
1 | package edu.harvard.seas.pl.abcdatalog.engine;
2 |
3 | /*-
4 | * #%L
5 | * AbcDatalog
6 | * %%
7 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
8 | * %%
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | *
12 | * 1. Redistributions of source code must retain the above copyright notice, this
13 | * list of conditions and the following disclaimer.
14 | *
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | *
19 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software without
21 | * specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
32 | * OF THE POSSIBILITY OF SUCH DAMAGE.
33 | * #L%
34 | */
35 |
36 | import edu.harvard.seas.pl.abcdatalog.engine.topdown.MstEngine;
37 | import org.junit.runner.RunWith;
38 | import org.junit.runners.Suite;
39 |
40 | @RunWith(Suite.class)
41 | @Suite.SuiteClasses({MstEngineTest.MyCoreTests.class, MstEngineTest.MyConjunctiveQueryTests.class})
42 | public class MstEngineTest {
43 | public static class MyCoreTests extends CoreTests {
44 |
45 | public MyCoreTests() {
46 | super(MstEngine::new);
47 | }
48 | }
49 |
50 | public static class MyConjunctiveQueryTests extends ConjunctiveQueryTests {
51 |
52 | public MyConjunctiveQueryTests() {
53 | super(MstEngine::new);
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/test/java/edu/harvard/seas/pl/abcdatalog/engine/RecursiveQsqEngineTest.java:
--------------------------------------------------------------------------------
1 | package edu.harvard.seas.pl.abcdatalog.engine;
2 |
3 | /*-
4 | * #%L
5 | * AbcDatalog
6 | * %%
7 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
8 | * %%
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | *
12 | * 1. Redistributions of source code must retain the above copyright notice, this
13 | * list of conditions and the following disclaimer.
14 | *
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | *
19 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software without
21 | * specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
32 | * OF THE POSSIBILITY OF SUCH DAMAGE.
33 | * #L%
34 | */
35 |
36 | import edu.harvard.seas.pl.abcdatalog.engine.topdown.RecursiveQsqEngine;
37 | import org.junit.runner.RunWith;
38 | import org.junit.runners.Suite;
39 |
40 | @RunWith(Suite.class)
41 | @Suite.SuiteClasses({
42 | RecursiveQsqEngineTest.MyCoreTests.class,
43 | RecursiveQsqEngineTest.MyConjunctiveQueryTests.class
44 | })
45 | public class RecursiveQsqEngineTest {
46 | public static class MyCoreTests extends CoreTests {
47 |
48 | public MyCoreTests() {
49 | super(RecursiveQsqEngine::new);
50 | }
51 | }
52 |
53 | public static class MyConjunctiveQueryTests extends ConjunctiveQueryTests {
54 |
55 | public MyConjunctiveQueryTests() {
56 | super(RecursiveQsqEngine::new);
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/test/java/edu/harvard/seas/pl/abcdatalog/engine/SemiNaiveEngineTest.java:
--------------------------------------------------------------------------------
1 | package edu.harvard.seas.pl.abcdatalog.engine;
2 |
3 | /*-
4 | * #%L
5 | * AbcDatalog
6 | * %%
7 | * Copyright (C) 2016 - 2021 President and Fellows of Harvard College
8 | * %%
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | *
12 | * 1. Redistributions of source code must retain the above copyright notice, this
13 | * list of conditions and the following disclaimer.
14 | *
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | *
19 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software without
21 | * specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
32 | * OF THE POSSIBILITY OF SUCH DAMAGE.
33 | * #L%
34 | */
35 |
36 | import edu.harvard.seas.pl.abcdatalog.engine.bottomup.sequential.SemiNaiveEngine;
37 | import org.junit.runner.RunWith;
38 | import org.junit.runners.Suite;
39 |
40 | @RunWith(Suite.class)
41 | @Suite.SuiteClasses({
42 | SemiNaiveEngineTest.MyCoreTests.class,
43 | SemiNaiveEngineTest.MyUnificationTests.class,
44 | SemiNaiveEngineTest.MyNegationTests.class,
45 | SemiNaiveEngineTest.MyConjunctiveQueryTests.class
46 | })
47 | public class SemiNaiveEngineTest {
48 | public static class MyCoreTests extends CoreTests {
49 |
50 | public MyCoreTests() {
51 | super(() -> new SemiNaiveEngine(true));
52 | }
53 | }
54 |
55 | public static class MyUnificationTests extends ExplicitUnificationTests {
56 |
57 | public MyUnificationTests() {
58 | super(() -> new SemiNaiveEngine(true));
59 | }
60 | }
61 |
62 | public static class MyNegationTests extends StratifiedNegationTests {
63 |
64 | public MyNegationTests() {
65 | super(() -> new SemiNaiveEngine(true));
66 | }
67 | }
68 |
69 | public static class MyConjunctiveQueryTests extends ConjunctiveQueryTests {
70 |
71 | public MyConjunctiveQueryTests() {
72 | super(() -> new SemiNaiveEngine(true));
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/test/java/edu/harvard/seas/pl/abcdatalog/util/datastructures/FactIndexerTest.java:
--------------------------------------------------------------------------------
1 | package edu.harvard.seas.pl.abcdatalog.util.datastructures;
2 |
3 | /*-
4 | * #%L
5 | * AbcDatalog
6 | * %%
7 | * Copyright (C) 2016 - 2024 President and Fellows of Harvard College
8 | * %%
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | *
12 | * 1. Redistributions of source code must retain the above copyright notice, this
13 | * list of conditions and the following disclaimer.
14 | *
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | *
19 | * 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software without
21 | * specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
32 | * OF THE POSSIBILITY OF SUCH DAMAGE.
33 | * #L%
34 | */
35 |
36 | import edu.harvard.seas.pl.abcdatalog.ast.*;
37 | import edu.harvard.seas.pl.abcdatalog.engine.AbstractTests;
38 | import java.util.function.Supplier;
39 | import org.junit.Assert;
40 | import org.junit.Test;
41 | import org.junit.runner.RunWith;
42 | import org.junit.runners.Suite;
43 |
44 | @RunWith(Suite.class)
45 | @Suite.SuiteClasses({
46 | FactIndexerTest.SetTests.class,
47 | FactIndexerTest.ConcurrentLinkedBagTests.class
48 | })
49 | public class FactIndexerTest {
50 | public static class SetTests extends AbstractFactIndexerTests {
51 | public SetTests() {
52 | super(FactIndexerFactory::createConcurrentSetFactIndexer);
53 | }
54 | }
55 |
56 | public static class ConcurrentLinkedBagTests extends AbstractFactIndexerTests {
57 | public ConcurrentLinkedBagTests() {
58 | super(FactIndexerFactory::createConcurrentQueueFactIndexer);
59 | }
60 | }
61 |
62 | public abstract static class AbstractFactIndexerTests extends AbstractTests {
63 | private final Supplier factIndexerFactory;
64 |
65 | public AbstractFactIndexerTests(Supplier factIndexerFactory) {
66 | super(
67 | () -> {
68 | throw new Error("Tests do not use engine=");
69 | });
70 | this.factIndexerFactory = factIndexerFactory;
71 | }
72 |
73 | @Test
74 | public void testSmallestFactSetIsReturnedFromFineIndex() {
75 | FactIndexer indexer = factIndexerFactory.get();
76 | indexer.addAll(parseFacts("f(a,x,b). f(b,x,b). f(c,x1,b). f(c,x2,b). f(c,x,d)."));
77 |
78 | Iterable result = indexer.indexInto(parseQuery("f(c,_,d)?"));
79 | int size = 0;
80 | for (PositiveAtom ignored : result) {
81 | ++size;
82 | }
83 | Assert.assertEquals(1, size);
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/third-party-licenses/THIRD-PARTY.txt:
--------------------------------------------------------------------------------
1 |
2 | Lists of 3 third-party dependencies.
3 | (Eclipse Public License 1.0) JUnit (junit:junit:4.13.2 - http://junit.org)
4 | (New BSD License) Hamcrest Core (org.hamcrest:hamcrest-core:1.3 - https://github.com/hamcrest/JavaHamcrest/hamcrest-core)
5 | (Apache License 2.0) FlatLaf (FlatLaf:3.1.1 - https://github.com/JFormDesigner/FlatLaf)
--------------------------------------------------------------------------------