<commit_before>/**
 * 
 */
package de.uni_jena.iaa.linktype.atomic.editors.grapheditor.commands;

import java.util.Iterator;
import java.util.Map.Entry;
import java.util.TreeMap;

import org.apache.commons.lang3.tuple.Pair;
import org.eclipse.core.runtime.Assert;
import org.eclipse.gef.commands.Command;

import de.hu_berlin.german.korpling.saltnpepper.salt.saltCommon.sDocumentStructure.SStructuredNode;
import de.hu_berlin.german.korpling.saltnpepper.salt.saltCore.SAnnotation;

/**
 * @author <NAME>
 *
 */
public class StructuredNodeAnnotateCommand extends Command {
	
	private SStructuredNode model;
	private TreeMap<String, Pair<String, String>> annotations = new TreeMap<String, Pair<String, String>>();
	
	@Override 
	public void execute() {
		// Remove all annotations; FIXME: Save them in TreeMap<String, Pair<String,String>> oldAnnotations for undo
		for (Iterator<SAnnotation> iterator = model.getSAnnotations().iterator(); iterator.hasNext();) {
			SAnnotation anno = (SAnnotation) iterator.next();
			String name = anno.getName();
			model.removeLabel(name);
			Assert.isTrue(!(model.getSAnnotations().contains(name))); // FIXME: Refactor to unit test method
		}
		// Create annotations from input
		for (Entry<String, Pair<String, String>> anno : getAnnotations().entrySet()) {
			model.createSAnnotation(anno.getValue().getLeft(), anno.getKey(), anno.getValue().getRight());
		}
	}
			 
	public void setModel(SStructuredNode model) {
		this.model = model;
	}

	/**
	 * @return the annotations
	 */
	public TreeMap<String,Pair<String,String>> getAnnotations() {<commit_msg>Fix behaviour that operates on a non-empty TreeMap for AnnotateCommands<commit_after>/**
 * 
 */
package de.uni_jena.iaa.linktype.atomic.editors.grapheditor.commands;

import java.util.Iterator;
import java.util.Map.Entry;
import java.util.TreeMap;

import org.apache.commons.lang3.tuple.Pair;
import org.eclipse.core.runtime.Assert;
import org.eclipse.gef.commands.Command;

import de.hu_berlin.german.korpling.saltnpepper.salt.saltCommon.sDocumentStructure.SStructuredNode;
import de.hu_berlin.german.korpling.saltnpepper.salt.saltCore.SAnnotation;

/**
 * @author <NAME>
 *
 */
public class StructuredNodeAnnotateCommand extends Command {
	
	private SStructuredNode model;
	private TreeMap<String, Pair<String, String>> annotations = new TreeMap<String, Pair<String, String>>();
	
	@Override 
	public void execute() {
		// Remove all annotations; FIXME: Save them in TreeMap<String, Pair<String,String>> oldAnnotations for undo
		for (Iterator<SAnnotation> iterator = model.getSAnnotations().iterator(); iterator.hasNext();) {
			SAnnotation anno = (SAnnotation) iterator.next();
			String name = anno.getName();
			model.removeLabel(name);
			Assert.isTrue(!(model.getSAnnotations().contains(name))); // FIXME: Refactor to unit test method
		}
		// Create annotations from input
		for (Entry<String, Pair<String, String>> anno : getAnnotations().entrySet()) {
			model.createSAnnotation(anno.getValue().getLeft(), anno.getKey(), anno.getValue().getRight());
		}
		// Empty TreeMap for next use!
		getAnnotations().clear();
	}
			 
	public void setModel(SStructuredNode model) {
		this.model = model;
	}

	/**
	 * @return the annotations
	 */
	public TreeMap<String,Pair<String,String>> getAnnotations() {
{'fraction_non_alphanumeric': 0.13345465574764936, 'fraction_numerical': 0.0006066120715802245, 'mean_word_length': 5.051376146788991, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, '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': '2377557', 'n_tokens_mistral': 1115, 'n_tokens_neox': 1024, 'n_words': 213}