Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ public boolean isDone() {
public double getPerformanceMeasure(Agent forAgent) {
Double pm = performanceMeasures.get(forAgent);
if (null == pm) {
pm = new Double(0);
// Fixing squid:s2129
pm = Double.valueOf(0);
performanceMeasures.put(forAgent, pm);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package aima.core.logic.fol.inference;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;

import aima.core.logic.fol.SubstVisitor;
import aima.core.logic.fol.Unifier;
Expand Down Expand Up @@ -106,47 +103,49 @@ public Object visitTermEquality(TermEquality equality, Object arg) {
}

public Object visitVariable(Variable variable, Object arg) {

if (null != (substitution = unifier.unify(toMatch, variable))) {
if (isValidMatch(toMatch, toMatchVariables, variable,
substitution)) {
// Fixing squid:s1066
if (null != (substitution = unifier.unify(toMatch, variable))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove these comments? The changes look fine.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also please have a look at the conflicts.

&& isValidMatch(toMatch, toMatchVariables, variable,
substitution)
) {
matchingTerm = variable;
}
}

return variable;
}

public Object visitConstant(Constant constant, Object arg) {
if (null != (substitution = unifier.unify(toMatch, constant))) {
if (isValidMatch(toMatch, toMatchVariables, constant,
substitution)) {
// Fixing squid:s1066
if (null != (substitution = unifier.unify(toMatch, constant))
&& isValidMatch(toMatch, toMatchVariables, constant,
substitution)
) {
matchingTerm = constant;
}
}

return constant;
}

public Object visitFunction(Function function, Object arg) {
if (null != (substitution = unifier.unify(toMatch, function))) {
if (isValidMatch(toMatch, toMatchVariables, function,
substitution)) {
// Fixing squid:S1066
if (null != (substitution = unifier.unify(toMatch, function))
&& isValidMatch(toMatch, toMatchVariables, function,
substitution)
) {
matchingTerm = function;
}
}

// Fixing squid:s2259
if (null == matchingTerm) {
// Try the Function's arguments
for (Term t : function.getArgs()) {
// Finish processing if have found a match
if (null != matchingTerm) {
break;
Optional<Function> optionalFunction = Optional.ofNullable(function);
optionalFunction.ifPresent(f-> {
for (Term t: f.getArgs()) {
// Finish processing if have found a match
if (null != matchingTerm) {
break;
}
t.accept(this, null);
}
t.accept(this, null);
}
});
}

return function;
}

Expand Down Expand Up @@ -176,9 +175,6 @@ protected class ReplaceMatchingTerm implements FOLVisitor {
private Term replaceWith = null;
private boolean replaced = false;

public ReplaceMatchingTerm() {
}

public AtomicSentence replace(AtomicSentence expression,
Term toReplace, Term replaceWith) {
this.toReplace = toReplace;
Expand All @@ -205,31 +201,29 @@ public Object visitTermEquality(TermEquality equality, Object arg) {
}

public Object visitVariable(Variable variable, Object arg) {
if (!replaced) {
if (toReplace.equals(variable)) {
// Fixing squid:s1066
if (!replaced
&& toReplace.equals(variable)) {
replaced = true;
return replaceWith;
}
}
return variable;
}

public Object visitConstant(Constant constant, Object arg) {
if (!replaced) {
if (toReplace.equals(constant)) {
if (!replaced
&& toReplace.equals(constant)) {
replaced = true;
return replaceWith;
}
}
return constant;
}

public Object visitFunction(Function function, Object arg) {
if (!replaced) {
if (toReplace.equals(function)) {
if (!replaced
&& toReplace.equals(function)) {
replaced = true;
return replaceWith;
}
}

List<Term> newTerms = new ArrayList<Term>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
*/
public class AbstractFOLVisitor implements FOLVisitor {

public AbstractFOLVisitor() {
}

protected Sentence recreate(Object ast) {
return ((Sentence) ast).copy();
}
Expand Down