Adapter class

To integrate Dungine into any application you must first identify the arguments and the conflicts between arguments. The Araucaria Argument class is used to store all arguments in an Araucaria argument map. The argument map is a tree or a series of trees composed of TreeVertex objects where each TreeVertex object corresponds to a node in the argument map. Conflict is provided by the rebuttal relation. The tricky thing in this integration is that we are only interested in the main arguments, not their premises. Thus we need to identify main arguments. To do this, we use two rules of thumb:

  1. Identify tree roots - these are main arguments.
  2. Identify arguments that are rebuttals of other arguments - these are main arguments.


Now we have enough information to begin building our adapter class. The basic idea in this integration is that our adapter class (AraucariaArgumentSource) will expose Araucaria main arguments (TreeVertex objects), wrapped in ArgKit Arguments, through the ArgKit ArgumentSource and DefeatSource interfaces. One slight annoyance here is that the classname Argument is used by both Araucaria and Dungine, so we will need to qualify the Dungine argument definitions. So, let us begin. First we will need two maps to store the ArgKit arguments and defeats:

Map<TreeVertex, org.argkit.Argument<TreeVertex>> arguments = 
    new HashMap<TreeVertex, org.argkit.Argument<TreeVertex>>();
Map<org.argkit.Argument<TreeVertex>, org.argkit.Argument<TreeVertex>> defeats = 
    new HashMap<org.argkit.Argument<TreeVertex>, org.argkit.Argument<TreeVertex>>();

Next we need two private functions to identify main arguments and check that we havent already created an ArgKit argument around an Araucaria argument:

	
private boolean isMainArgument(TreeVertex vertex) {
	return (vertex.m_hasParent==false) || (vertex.m_refutation==true);
}

private org.argkit.Argument<TreeVertex> addArgument(TreeVertex vertex) {
	if (arguments.containsKey(vertex)) {
		return arguments.get(vertex);
	} else {
		org.argkit.Argument<TreeVertex> argument = 
		    new org.argkit.Argument<TreeVertex>(vertex);
		arguments.put(vertex, argument);
		return argument;
	}
}

Now that we have set up our data structures and useful methods, we can create the constructor for our adapter class. This constructor accepts an Araucaria Argument object as a parameter and populates our two maps for storing arguments and defeats.

public AraucariaArgumentSource(Argument argument) {
	super();
	Iterator iterator = argument.tree.m_vertexList.iterator();
	while (iterator.hasNext()) {
		TreeVertex vertex = (TreeVertex) iterator.next();
		if (vertex.m_hasParent==false) {
			addArgument(vertex);
		} else if (vertex.m_refutation==true) {
			org.argkit.Argument<TreeVertex> arg = addArgument(vertex);
			// find ultimate parent of the parent of this one
			TreeVertex candidate = vertex.m_parent;
			while (!isMainArgument(candidate)) {
				candidate = candidate.m_parent;
			}
			// populate defeats map
			defeats.put(addArgument(candidate), arg);
		}
	}
}

Now all we need to do is implement the ArgumentSource and DefeatSource interfaces.

public Collection<? extends org.argkit.Argument<TreeVertex>> getAllArguments() {
	return arguments.values();
}
public Collection<? extends org.argkit.Argument<TreeVertex>> getArguments(TreeVertex claim) {
	List<org.argkit.Argument<TreeVertex>> result = new ArrayList<org.argkit.Argument<TreeVertex>>();
	if (arguments.containsKey(claim)) result.add(arguments.get(claim));
	return result;
}

public Collection<? extends org.argkit.Argument<TreeVertex>> agetDefeaters(org.argkit.Argument<TreeVertex> argument) {
	List<org.argkit.Argument<TreeVertex>> result = new ArrayList<org.argkit.Argument<TreeVertex>>();
	if (defeats.containsKey(argument)) result.add(defeats.get(argument));
	return result;
}

Et voila. Our adapter class is complete and all we need do now is update the Aracuaria GUI so that it knows how to use Dungine.