<commit_before>/**
 * Converts requirement file(.docx) to  EMF model instance
 * 
 * @author <EMAIL>
 */

package eu.modelwriter.architecture.textconnectors.docx;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Stack;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMLResourceFactoryImpl;

import SimpleRequirementMM.Priority;
import SimpleRequirementMM.Product;
import SimpleRequirementMM.Requirement;
import SimpleRequirementMM.RequirementLevel;
import SimpleRequirementMM.SimpleRequirementMMFactory;

public class Docx2ReqModelConverter {

	private static Product product;

	// Requirement property keywords
	private final static String REQUIREMENT_NAME = "Name";
	private final static String REQUIREMENT_DESCRIPTION = "Description";
	private final static String REQUIREMENT_REFINE = "Refine";
	private final static String REQUIREMENT_DEPENDENCY_TO = "Dependency to ";
	private final static String REQUIREMENT_PRIORITY = "Priority";
	private final static String REQUIREMENT_PRIORITY_MANDATORY = "Mandatory";

	//private static Map<Requirement,String> requirementsMap;

	// Stores levels 
	private static Stack<RequirementLevel> requirementLevelStack;

	// Maps requirement level object and their levels
	private static Map<RequirementLevel,Integer> requirementLevelMap;

	// Maps styles and their levels
	private static Map<String,Integer> headingMap;

	// Maps source and target requirement's Ids
	public static Map<String, String> dependenceyToMultiMap;

	// Maps source and target requirement's Ids
	public static Map<String, String> refineMultiMap;

	// Maps requirement id and corresponding requirement object
	public static Map<String, Requirement> requirementMultiMap;

	public static void main(String[] args)throws Exception 
	{
		//requirementsMap = new HashMap<Requirement,String>();
		requirementLevelStack = new Stack<RequirementLevel>();

		requirementLevelMap = new HashMap<RequirementLevel, Integer>();
		headingMap = new HashMap<String,Integer>();

		dependenceyToMultiMap = new HashMap<String, String>();
		refineMultiMap = new HashMap<String, String>();
		requirementMultiMap = new HashMap<String, Requirement>();

		// higher level is Heading1 in a word file
		//headingMap.put("NoSpacing", 0);	
		headingMap.put("Heading1", 1);
		headingMap.put("Heading2", 2);
		headingMap.put("Heading3", 3);
		headingMap.put("Heading4", 4);
		headingMap.put("Heading5", 5);
		headingMap.put("Heading6", 6);
		headingMap.put("Heading7", 7);
		headingMap.put("Heading8", 8);
		headingMap.put("Heading9", 9);

		XWPFDocument docx = new XWPFDocument(new FileInputStream("Test Documents/SampleRequirementDocument.docx"));

		//XWPFWordExtractor we = new XWPFWordExtractor(docx);

		//XWPFStyles styles = docx.getStyles();

		List<XWPFParagraph> paragraphList = docx.getParagraphs();

		SimpleRequirementMMFactory factory = SimpleRequirementMMFactory.eINSTANCE;

		//int currentIndex = 0;
		int firstParagraphCounter = 0;
		product = factory.createProduct();

		Requirement requirement = null;
		Requirement previousRequirement = null;

		// Regular expression for requirement id
		String pattern = "(EM-HLR-F-REQ-[0-9]{3})";
		Pattern p = Pattern.compile(pattern);

		for(XWPFParagraph paragraph : paragraphList){

			//boolean b = paragraph.getRun().isBold();
			firstParagraphCounter++;

			// For debug
		    String paragraphText = paragraph.getText().trim();

			if( paragraph != null && paragraphText != ""){

				// first paragraph element
				if(firstParagraphCounter == 1){<commit_msg>* minor changes<commit_after>/**
 * Converts requirement file(.docx) to  EMF model instance
 * 
 * @author <EMAIL>
 */

package eu.modelwriter.architecture.textconnectors.docx;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Stack;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMLResourceFactoryImpl;

import SimpleRequirementMM.Priority;
import SimpleRequirementMM.Product;
import SimpleRequirementMM.Requirement;
import SimpleRequirementMM.RequirementLevel;
import SimpleRequirementMM.SimpleRequirementMMFactory;

public class Docx2ReqModelConverter {

	private static Product product;

	// Requirement property keywords
	private final static String REQUIREMENT_NAME = "Name";
	private final static String REQUIREMENT_DESCRIPTION = "Description";
	private final static String REQUIREMENT_REFINE = "Refine";
	private final static String REQUIREMENT_DEPENDENCY_TO = "Dependency to ";
	private final static String REQUIREMENT_PRIORITY = "Priority";
	private final static String REQUIREMENT_PRIORITY_MANDATORY = "Mandatory";

	//private static Map<Requirement,String> requirementsMap;

	// Stores levels 
	private static Stack<RequirementLevel> requirementLevelStack;

	// Maps requirement level object and their levels
	private static Map<RequirementLevel,Integer> requirementLevelMap;

	// Maps styles and their levels
	private static Map<String,Integer> headingMap;

	// Maps source and target requirement's Ids
	public static Map<String, String> dependenceyToMultiMap;

	// Maps source and target requirement's Ids
	public static Map<String, String> refineMultiMap;

	// Maps requirement id and corresponding requirement object
	public static Map<String, Requirement> requirementMultiMap;

	public static void main(String[] args)throws Exception 
	{
		//requirementsMap = new HashMap<Requirement,String>();
		requirementLevelStack = new Stack<RequirementLevel>();

		requirementLevelMap = new HashMap<RequirementLevel, Integer>();
		headingMap = new HashMap<String,Integer>();

		dependenceyToMultiMap = new HashMap<String, String>();
		refineMultiMap = new HashMap<String, String>();
		requirementMultiMap = new HashMap<String, Requirement>();

		// higher level is Heading1 in a word file
		//headingMap.put("NoSpacing", 0);	
		headingMap.put("Heading1", 1);
		headingMap.put("Heading2", 2);
		headingMap.put("Heading3", 3);
		headingMap.put("Heading4", 4);
		headingMap.put("Heading5", 5);
		headingMap.put("Heading6", 6);
		headingMap.put("Heading7", 7);
		headingMap.put("Heading8", 8);
		headingMap.put("Heading9", 9);

		XWPFDocument docx = new XWPFDocument(new FileInputStream("Test Documents/SampleRequirementDocument.docx"));

		//XWPFWordExtractor we = new XWPFWordExtractor(docx);

		//XWPFStyles styles = docx.getStyles();

		List<XWPFParagraph> paragraphList = docx.getParagraphs();

		SimpleRequirementMMFactory factory = SimpleRequirementMMFactory.eINSTANCE;

		//int currentIndex = 0;
		int firstParagraphCounter = 0;
		product = factory.createProduct();

		Requirement requirement = null;
		Requirement previousRequirement = null;

		// Regular expression for requirement id
		String pattern = "(EM-HLR-F-REQ-[0-9]{3})";
		Pattern p = Pattern.compile(pattern);

		for(XWPFParagraph paragraph : paragraphList){

			firstParagraphCounter++;

			// For debug
		    // String paragraphText = paragraph.getText().trim();

			if( paragraph != null && paragraph.getText().trim() != ""){

				// first paragraph element
				if(firstParagraphCounter == 1){
{'fraction_non_alphanumeric': 0.10557221389305348, 'fraction_numerical': 0.006746626686656672, 'mean_word_length': 5.3886671987230645, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, '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': '4270310', 'n_tokens_mistral': 2557, 'n_tokens_neox': 2342, 'n_words': 580}