/**
 * 
 */
package de.uni_jena.iaa.linktype.atomic.core.corpus;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;

import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.EList;

import de.hu_berlin.german.korpling.saltnpepper.salt.graph.GRAPH_TRAVERSE_TYPE;
import de.hu_berlin.german.korpling.saltnpepper.salt.graph.Node;
import de.hu_berlin.german.korpling.saltnpepper.salt.saltCommon.sDocumentStructure.SDocumentGraph;
import de.hu_berlin.german.korpling.saltnpepper.salt.saltCommon.sDocumentStructure.SSpan;
import de.hu_berlin.german.korpling.saltnpepper.salt.saltCommon.sDocumentStructure.STYPE_NAME;
import de.hu_berlin.german.korpling.saltnpepper.salt.saltCommon.sDocumentStructure.SToken;

/**
 * Provides different services related to the SDocumentGraph.
 * 
 * @author Stephan Druskat
 * 
 */
public class GraphService {

	/**
	 * @param span
	 * @return
	 */
	public static EList<SToken> getOverlappedTokens(SSpan span) {
		EList<SToken> overlappedTokens = span.getSDocumentGraph().getOverlappedSTokens(span, new BasicEList<STYPE_NAME>(Arrays.asList(STYPE_NAME.SSPANNING_RELATION)));
		EList<SToken> sortedTokens = span.getSDocumentGraph().getSortedSTokenByText(overlappedTokens);
		return sortedTokens;
	}

	/**
	 * @param list
	 * @return
	 */
	public static EList<SToken> getOrderedTokensForSentenceSpans(List<?> sentenceSpanList) {
		EList<SToken> unorderedTokens = new BasicEList<SToken>();
		for (Object listElement : sentenceSpanList) {
			if (!(listElement instanceof SSpan)) {
				// sentenceSpanList cannot be a valid sentenceSpanList!
				return null;
			}
			SSpan span = (SSpan) listElement;
			unorderedTokens.addAll(getOverlappedTokens(span));
		}
		return ((SSpan) sentenceSpanList.get(0)).getSDocumentGraph().getSortedSTokenByText(unorderedTokens);
	}
	
	/**
	 * @return
	 */
	public static List<Node> getSentenceGraph(EList<SToken> tokens) {
		SDocumentGraph graph = tokens.get(0).getSDocumentGraph();
		ArrayList<Node> subGraph = new ArrayList<Node>();
		SentenceGraphTraverser traverser = new SentenceGraphTraverser();
		traverser.setTokenSet(new HashSet<SToken>(tokens));
		traverser.setGraph(graph);
		graph.traverse(tokens, GRAPH_TRAVERSE_TYPE.BOTTOM_UP_BREADTH_FIRST, "subtree", traverser, false);
		subGraph.addAll(traverser.getNodeSet());
		return subGraph;
	}

}

@@ -2372,12 +2372,514 @@
 raph;%0A%09%7D
+%0A%09%0A%09/* @param checkedElement%0A%09 * @return%0A%09 */%0A%09public static HashSet%3CSSpan%3E getLinkedSentences(SSpan checkedSentence) %7B%0A%09%09EList%3CSToken%3E tokens = GraphService.getOverlappedTokens(checkedSentence);%0A%09%09LinkedSentencesTraverser traverser = new LinkedSentencesTraverser();%0A%09%09traverser.setTokenSet(new HashSet%3CSToken%3E(tokens));%0A%09%09checkedSentence.getSDocumentGraph().traverse(tokens, GRAPH_TRAVERSE_TYPE.BOTTOM_UP_BREADTH_FIRST, %22linkedSentences%22, traverser, false);%0A%09%09return traverser.getLinkedSentences();%0A%09%7D
 %0A%0A%7D%0A

Put GraphService.getLinkedSentences() back into codebase