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

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

import org.eclipse.core.runtime.Assert;
import org.eclipse.gef.commands.Command;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Display;

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

/**
 * @author <NAME>
 *
 */
public class TokenAnnotateCommand extends Command {
	
	private String annotationInput;
	private SToken model;
	private TreeMap<String, String> annotations = new TreeMap<String, String>();
	
	@Override 
	public void execute() {
		for (Iterator<SAnnotation> iterator = model.getSAnnotations().iterator(); iterator.hasNext();) {
			SAnnotation anno = (SAnnotation) iterator.next();
			String namespace = anno.getNamespace();
			String name = anno.getName();
			model.removeLabel(name);
			Assert.isTrue(!(model.getSAnnotations().contains(name))); // FIXME: Refactor to unit test method
		}
		String lineSeparator = System.getProperty("line.separator");
		String[] keyValuePairs = annotationInput.split(lineSeparator);
		for (int i = 0; i < keyValuePairs.length; i++) {
			String[] keyValuePair = keyValuePairs[i].split(":");
			String annoKey = keyValuePair[0];
			String annoValue = keyValuePair[1];
			String previousValue = annotations.put(annoKey, annoValue);
			if (previousValue != null) {
				boolean shouldAnnoChange = MessageDialog.openConfirm(Display.getCurrent().getActiveShell(), "Duplicate annotation found!", "Duplicate annotation!\n"
						+ "Should the previous value of " + annoKey + " (" + previousValue + ") be overwritten with "
						+ "the value " + annoValue + "?");
				if (shouldAnnoChange) {
					// Do nothing, key-value pair is already in TreeMap
				}
				else {
					annotations.put(annoKey, previousValue);
				}
			}
		}<commit_msg>Clean up<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.eclipse.core.runtime.Assert;
import org.eclipse.gef.commands.Command;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Display;

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

/**
 * @author <NAME>
 *
 */
public class TokenAnnotateCommand extends Command {
	
	private String annotationInput;
	private SToken model;
	private TreeMap<String, String> annotations = new TreeMap<String, String>();
	
	@Override 
	public void execute() {
		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
		}
		String lineSeparator = System.getProperty("line.separator");
		String[] keyValuePairs = annotationInput.split(lineSeparator);
		for (int i = 0; i < keyValuePairs.length; i++) {
			String[] keyValuePair = keyValuePairs[i].split(":");
			String annoKey = keyValuePair[0];
			String annoValue = keyValuePair[1];
			String previousValue = annotations.put(annoKey, annoValue);
			if (previousValue != null) {
				boolean shouldAnnoChange = MessageDialog.openConfirm(Display.getCurrent().getActiveShell(), "Duplicate annotation found!", "Duplicate annotation!\n"
						+ "Should the previous value of " + annoKey + " (" + previousValue + ") be overwritten with "
						+ "the value " + annoValue + "?");
				if (shouldAnnoChange) {
					// Do nothing, key-value pair is already in TreeMap
				}
				else {
					annotations.put(annoKey, previousValue);
				}
			}
		}
{'fraction_non_alphanumeric': 0.12975951903807614, 'fraction_numerical': 0.001503006012024048, 'mean_word_length': 4.530470914127424, 'pattern_counts': {'":': 2, '<': 13, '<?xml version=': 0, '>': 11, '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': '3443324', 'n_tokens_mistral': 1387, 'n_tokens_neox': 1234, 'n_words': 262}