<commit_before><p>
As well as interacting with Projog using the console application it is also possible to embed Projog in your Java applications.
The steps required for applications to interact with Projog are as follows:
<ul>
<li>Create a new <a href="javadoc/org/projog/api/Projog.html" title="class in org.projog.api"><code>Projog</code></a> instance.</li>
<li>Load in clauses and facts using <a href="javadoc/org/projog/api/Projog.html#consultFile-java.io.File-"><code>Projog.consultFile(File)</code></a> or <a href="javadoc/org/projog/api/Projog.html#consultReader-java.io.Reader-"><code>Projog.consultReader(Reader)</code></a>.</li>
<li>Create a <a href="javadoc/org/projog/api/QueryStatement.html" title="class in org.projog.api"><code>QueryStatement</code></a> by using <a href="javadoc/org/projog/api/Projog.html#query-java.lang.String-"><code>Projog.query(String)</code></a>.</li>
<li>Create a <a href="javadoc/org/projog/api/QueryResult.html" title="class in org.projog.api"><code>QueryResult</code></a> by using <a href="javadoc/org/projog/api/QueryStatement.html#getResult--"><code>QueryStatement.getResult()</code></a>.</li>
<li>Iterate through all possible solutions to the query by using <a href="javadoc/org/projog/api/QueryResult.html#next--"><code>QueryResult.next()</code></a>.</li>
<li>For each solution get the <a href="javadoc/org/projog/core/term/Term.html" title="interface in org.projog.core.term"><code>Term</code></a> instantiated to a <a href="javadoc/org/projog/core/term/Variable.html" title="class in org.projog.core.term"><code>Variable</code></a> in the query by calling <a href="javadoc/org/projog/api/QueryResult.html#getTerm-java.lang.String-"><code>QueryResult.getTerm(String)</code></a>.</li>
</ul>
</p>

<h3>Example usage</h3>

<p>
Contents of <code>org/projog/example/ProjogExample.java</code>:
</p>

<div class="code"><code>package org.projog.example;<br>
<br>
import java.io.File;<br>
<br>
import org.projog.api.Projog;<br>
import org.projog.api.QueryResult;<br>
import org.projog.api.QueryStatement;<br>
import org.projog.core.term.Atom;<br>
<br>
public class ProjogExample {<br>
&nbsp;&nbsp;&nbsp;public static void main(String[] args) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Projog p = new Projog();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p.consultFile(new File("test.pl"));<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;QueryStatement s1 = p.query("test(X,Y).");<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;QueryResult r1 = s1.getResult();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while (r1.next()) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("X = " + r1.getTerm("X") + " Y = " + r1.getTerm("Y"));<br><commit_msg>corrected links to javadoc<commit_after><p>
As well as interacting with Projog using the console application it is also possible to embed Projog in your Java applications.
The steps required for applications to interact with Projog are as follows:
<ul>
<li>Create a new <a href="javadoc/org/projog/api/Projog.html" title="class in org.projog.api"><code>Projog</code></a> instance.</li>
<li>Load in clauses and facts using <a href="javadoc/org/projog/api/Projog.html#consultFile(java.io.File)"><code>Projog.consultFile(File)</code></a> or <a href="javadoc/org/projog/api/Projog.html#consultReader(java.io.Reader)"><code>Projog.consultReader(Reader)</code></a>.</li>
<li>Create a <a href="javadoc/org/projog/api/QueryStatement.html" title="class in org.projog.api"><code>QueryStatement</code></a> by using <a href="javadoc/org/projog/api/Projog.html#query(java.lang.String)"><code>Projog.query(String)</code></a>.</li>
<li>Create a <a href="javadoc/org/projog/api/QueryResult.html" title="class in org.projog.api"><code>QueryResult</code></a> by using <a href="javadoc/org/projog/api/QueryStatement.html#getResult()"><code>QueryStatement.getResult()</code></a>.</li>
<li>Iterate through all possible solutions to the query by using <a href="javadoc/org/projog/api/QueryResult.html#next()"><code>QueryResult.next()</code></a>.</li>
<li>For each solution get the <a href="javadoc/org/projog/core/term/Term.html" title="interface in org.projog.core.term"><code>Term</code></a> instantiated to a <a href="javadoc/org/projog/core/term/Variable.html" title="class in org.projog.core.term"><code>Variable</code></a> in the query by calling <a href="javadoc/org/projog/api/QueryResult.html#getTerm(java.lang.String)"><code>QueryResult.getTerm(String)</code></a>.</li>
</ul>
</p>

<h3>Example usage</h3>

<p>
Contents of <code>org/projog/example/ProjogExample.java</code>:
</p>

<div class="code"><code>package org.projog.example;<br>
<br>
import java.io.File;<br>
<br>
import org.projog.api.Projog;<br>
import org.projog.api.QueryResult;<br>
import org.projog.api.QueryStatement;<br>
import org.projog.core.term.Atom;<br>
<br>
public class ProjogExample {<br>
&nbsp;&nbsp;&nbsp;public static void main(String[] args) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Projog p = new Projog();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p.consultFile(new File("test.pl"));<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;QueryStatement s1 = p.query("test(X,Y).");<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;QueryResult r1 = s1.getResult();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while (r1.next()) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("X = " + r1.getTerm("X") + " Y = " + r1.getTerm("Y"));<br>
{'fraction_non_alphanumeric': 0.2059751345333086, 'fraction_numerical': 0.0029690109482278714, 'mean_word_length': 6.857142857142857, 'pattern_counts': {'":': 0, '<': 173, '<?xml version=': 0, '>': 173, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7537608', 'n_tokens_mistral': 2044, 'n_tokens_neox': 1951, 'n_words': 338}