Skip to content
Snippets Groups Projects
Select Git revision
  • dac27b04aff12a28c3c020464cd93b380307952f
  • master default protected
2 results

Affix.java

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    Affix.java 2.67 KiB
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.HashSet;
    import java.util.Map;
    import java.util.Set;
    
    public class Affix 
    {
    	private Map<String, ArrayList<String>> morphemeWordList = new HashMap<String,ArrayList<String>>();
    	private ArrayList<String> filteredWords = new ArrayList<String>();
    	private String wordclass = "";
    	private String affixtype = "";
    	private int startdate = 0;
    	private int enddate = 0;
    	
    	public Affix(ArrayList<String> filteredWords, int startdate, int enddate, String wordclass, String affixtype)
    	{
    		this.filteredWords = filteredWords;
    		this.affixtype = affixtype;
    		this.wordclass = wordclass;
    		this.startdate = startdate;
    		this.enddate = enddate;
    		processMorphemes();
    	}
    	
    	public Map<String, ArrayList<String>> getMorphemeWordList()
    	{
    		return morphemeWordList;
    	}
    	
    	private void processMorphemes()
    	{
    	Set<String> wordTypes = new HashSet<String>(filteredWords);
    	
    	Map<String, Integer> affixMorpheme = new HashMap<String,Integer>();
    	//Map<String, ArrayList<String>> morphemeWordList = new HashMap<String,ArrayList<String>>();
    
    	for (String word : wordTypes)
    	{
    		AffixStripper as = new AffixStripper(word);
    		if (affixtype.equals("_su01")) 
    			{
    			//System.out.println("Suffix morpheme list will be generated");
    			affixMorpheme = as.getSuffixMorphem(); //contains all suffix morphemes found in noun
    			}
    		else if (affixtype.equals("_pr01"))
    		{
    			affixMorpheme = as.getPrefixMorphem(); //contains all prefix morphemes found in noun
    		}
    		else
    		{
    			System.out.println("Affixtype not known");
    		}
    		if (!affixMorpheme.isEmpty())
    		{
    			
    			for (String morpheme : affixMorpheme.keySet())
    			{
    				ArrayList<String> wordsWithAffix = new ArrayList<String>();
    
    				if (morphemeWordList.get(morpheme)!=null)//only for the first iteration when the morphemeWordList does not contain any data
    				{
    					// keep the values of morphemeWordList that were written to it previously
    					wordsWithAffix = morphemeWordList.get(morpheme);
    					//System.out.println("First Iteration: " + morphemeWordList.get(morpheme));
    				}
    				//System.out.println(word + " " + morpheme);
    				//call the Oxford class and check if the morpheme occurs in the noun
    				OED ox = new OED(word, morpheme, wordclass, affixtype, startdate, enddate);
    				
    				if (ox.processOEDRequest())
    				{
    					wordsWithAffix.add(word);
    					morphemeWordList.put(morpheme, wordsWithAffix);
    					//System.out.println("when OED was consulted: " + word + ": " + morpheme);
    				}
    				
    				//if (number_of_queries == 1000) break;
    			}
    			//System.out.println("Outside the second for-loop: " + word + ": " + affixMorpheme.keySet());
    		}
    	}
    }
    }