<commit_before>package eu.scasefp7.eclipse.reqeditor.ui;

import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.eclipse.ui.editors.text.TextEditor;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import eu.scasefp7.eclipse.reqeditor.helpers.MyProgressMonitor;

/**
 * This class reads an sbd file and extracts all requirements and annotations. Additionally, it recreates the file when
 * any changes are made.
 * 
 * @author themis
 */
public class SBDPhrasesReader extends RequirementsReader {

	/**
	 * The main document element of the sbd file.
	 */
	private Element doc;

	/**
	 * Initializes this reader.
	 */
	public SBDPhrasesReader() {
		super();
	}

	/**
	 * Initializes this reader providing the raw editor object.
	 * 
	 * @param editor the editor containing the raw rws file.
	 */
	public SBDPhrasesReader(TextEditor editor) {
		super(editor);
	}

	/**
	 * Parses data from an {@link InputStream} and extracts the requirements and the annotations.
	 * 
	 * @param scanner the {@link InputStream} to parse data from.
	 */
	public void parseData(InputStream stream) {
		DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
		DocumentBuilder db;
		try {
			db = dbf.newDocumentBuilder();
			Document dom = db.parse(stream);
			doc = dom.getDocumentElement();
			doc.normalize();

			Node root = doc.getElementsByTagName("auth.storyboards:StoryboardDiagram").item(0);
			NodeList nodes = root.getChildNodes();
			int k = 0;
			for (int i = 0; i < nodes.getLength(); i++) {
				Node node = nodes.item(i);
				if (node.getNodeName().equals("storyboardactions")) {
					k++;
					requirements.add(new Requirement(k, node.getAttributes().getNamedItem("name").getTextContent()));
					if (node.getAttributes().getNamedItem("annotations") != null) {
						String[] lineAnnotations = node.getAttributes().getNamedItem("annotations").getTextContent()
								.split("\\\\n");
						for (String line : lineAnnotations) {<commit_msg>Fixed minor issue for not reading empty annotations of storyboards<commit_after>package eu.scasefp7.eclipse.reqeditor.ui;

import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.eclipse.ui.editors.text.TextEditor;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import eu.scasefp7.eclipse.reqeditor.helpers.MyProgressMonitor;

/**
 * This class reads an sbd file and extracts all requirements and annotations. Additionally, it recreates the file when
 * any changes are made.
 * 
 * @author themis
 */
public class SBDPhrasesReader extends RequirementsReader {

	/**
	 * The main document element of the sbd file.
	 */
	private Element doc;

	/**
	 * Initializes this reader.
	 */
	public SBDPhrasesReader() {
		super();
	}

	/**
	 * Initializes this reader providing the raw editor object.
	 * 
	 * @param editor the editor containing the raw rws file.
	 */
	public SBDPhrasesReader(TextEditor editor) {
		super(editor);
	}

	/**
	 * Parses data from an {@link InputStream} and extracts the requirements and the annotations.
	 * 
	 * @param scanner the {@link InputStream} to parse data from.
	 */
	public void parseData(InputStream stream) {
		DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
		DocumentBuilder db;
		try {
			db = dbf.newDocumentBuilder();
			Document dom = db.parse(stream);
			doc = dom.getDocumentElement();
			doc.normalize();

			Node root = doc.getElementsByTagName("auth.storyboards:StoryboardDiagram").item(0);
			NodeList nodes = root.getChildNodes();
			int k = 0;
			for (int i = 0; i < nodes.getLength(); i++) {
				Node node = nodes.item(i);
				if (node.getNodeName().equals("storyboardactions")) {
					k++;
					requirements.add(new Requirement(k, node.getAttributes().getNamedItem("name").getTextContent()));
					if (node.getAttributes().getNamedItem("annotations") != null
							&& !node.getAttributes().getNamedItem("annotations").getNodeValue().equals("")) {
						String[] lineAnnotations = node.getAttributes().getNamedItem("annotations").getTextContent()
								.split("\\\\n");
						for (String line : lineAnnotations) {
{'fraction_non_alphanumeric': 0.11928783382789318, 'fraction_numerical': 0.0035608308605341245, 'mean_word_length': 4.3502645502645505, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 18}, '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': '4268450', 'n_tokens_mistral': 1652, 'n_tokens_neox': 1475, 'n_words': 372}