2018-01-10 09:53:07 +00:00
|
|
|
package asp;
|
|
|
|
|
|
|
|
import de.dhbwstuttgart.parser.NullToken;
|
2018-07-17 17:56:01 +00:00
|
|
|
import de.dhbwstuttgart.sat.asp.ASPUnify;
|
2018-02-27 18:10:16 +00:00
|
|
|
import de.dhbwstuttgart.sat.asp.parser.ASPParser;
|
2018-03-07 21:41:00 +00:00
|
|
|
import de.dhbwstuttgart.sat.asp.writer.ASPFactory;
|
2018-01-10 09:53:07 +00:00
|
|
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
|
|
|
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
2018-02-27 18:10:16 +00:00
|
|
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
2018-01-10 09:53:07 +00:00
|
|
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
|
|
|
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
|
|
|
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
2018-02-27 18:10:16 +00:00
|
|
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
2018-01-10 09:53:07 +00:00
|
|
|
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
import java.io.*;
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
public class ClingoTest {
|
|
|
|
public static final String tempDirectory = "/tmp/";
|
2018-02-27 18:10:16 +00:00
|
|
|
private final TypePlaceholder testType = TypePlaceholder.fresh(new NullToken());
|
2018-01-10 09:53:07 +00:00
|
|
|
@Test
|
2018-02-19 10:33:08 +00:00
|
|
|
public void test() throws IOException, InterruptedException, ClassNotFoundException {
|
2018-01-10 09:53:07 +00:00
|
|
|
String content = "";
|
2018-03-07 21:41:00 +00:00
|
|
|
content = ASPFactory.generateASP(this.getPairs(), this.getFC());
|
2018-01-10 09:53:07 +00:00
|
|
|
|
|
|
|
PrintWriter writer = new PrintWriter(tempDirectory + "test.lp", "UTF-8");
|
|
|
|
writer.println(content);
|
|
|
|
writer.close();
|
|
|
|
|
2018-07-17 17:56:01 +00:00
|
|
|
ASPUnify clingo = new ASPUnify(Arrays.asList(new File(tempDirectory + "test.lp")));
|
2018-02-27 18:10:16 +00:00
|
|
|
String result = clingo.runClingo();
|
|
|
|
System.out.println(result);
|
|
|
|
ResultSet resultSet = ASPParser.parse(result, Arrays.asList(testType));
|
|
|
|
RefTypeOrTPHOrWildcardOrGeneric resolvedType = resultSet.resolveType(testType).resolvedType;
|
|
|
|
assert resolvedType.toString().equals(ASTFactory.createObjectType().toString());
|
2018-01-10 09:53:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Collection<ClassOrInterface> getFC() {
|
|
|
|
Set<ClassOrInterface> ret = new HashSet<>();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ConstraintSet<Pair> getPairs() {
|
|
|
|
ConstraintSet<Pair> ret = new ConstraintSet<>();
|
2018-02-27 18:10:16 +00:00
|
|
|
ret.addUndConstraint(new Pair(testType, ASTFactory.createObjectType(), PairOperator.EQUALSDOT));
|
2018-01-10 09:53:07 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|