All Downloads are FREE. Search and download functionalities are using the official Maven repository.

it.uniroma2.art.coda.structures.SuggOntologyCoda Maven / Gradle / Ivy

There is a newer version: 2.0.2
Show newest version
package it.uniroma2.art.coda.structures;

import it.uniroma2.art.coda.exception.ValueNotPresentDueToConfigurationException;
import it.uniroma2.art.coda.pearl.model.BaseProjectionRule;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.uima.jcas.tcas.Annotation;

/**
 * @author Andrea Turbati
 */

public class SuggOntologyCoda {

	private Annotation ann;
	private Map> suggestedBaseRuleIdToInsertARTTtripleMap;
	private Map> suggestedBaseRuleIdToDeleteARTTtripleMap;
	private Map baseProjectionRuleMap;

	private Map nodeNameToNodeAssignmentMap;

	// the structure created by the projection disambiguation containing the selected projection rules
	//SelectedProjectionRules selProjRules;
	// all the structure returned by CODACore (merging the other structure and adding the missing information)
	//CodaFinalSuggestions codaFinalSuggs;

	
	public SuggOntologyCoda(Annotation ann, boolean addNodeAssignmentMap){
		this.ann = ann;
		suggestedBaseRuleIdToInsertARTTtripleMap = new HashMap<>();
		suggestedBaseRuleIdToDeleteARTTtripleMap = new HashMap<>();
		baseProjectionRuleMap = new HashMap<>();
		if (addNodeAssignmentMap) {
			nodeNameToNodeAssignmentMap = new HashMap<>();
		} else {
			nodeNameToNodeAssignmentMap = null;
		}
	}
	
	
	public void addProjectionRule(BaseProjectionRule bpr){
		baseProjectionRuleMap.put(bpr.getId(), bpr);
	}
	
	public Set getBaseProjectionRulesIdList(){
		return baseProjectionRuleMap.keySet();
	}
	
	public BaseProjectionRule getBaseProjectionRulesFromId(String baseProjRuleId){
		return baseProjectionRuleMap.get(baseProjRuleId);
	}
	
	//all the methods to deal with insert Triples
	public void addSuggestedInsertTriple(String baseRuleId, CODATriple codaTriple){
		if(!suggestedBaseRuleIdToInsertARTTtripleMap.containsKey(baseRuleId)){
			suggestedBaseRuleIdToInsertARTTtripleMap.put(baseRuleId, new ArrayList());
		}
		suggestedBaseRuleIdToInsertARTTtripleMap.get(baseRuleId).add(codaTriple);
	}
	
	public void addSuggestedInsertTripleList(String baseRuleId, List codaTripleList){
		if(!suggestedBaseRuleIdToInsertARTTtripleMap.containsKey(baseRuleId)){
			suggestedBaseRuleIdToInsertARTTtripleMap.put(baseRuleId, new ArrayList());
		}
		suggestedBaseRuleIdToInsertARTTtripleMap.get(baseRuleId).addAll(codaTripleList);
	}
	

	
	public List getInsertARTTripleListFromBaseProjRuleId(String baseProjRuleId){
		List rv = suggestedBaseRuleIdToInsertARTTtripleMap.get(baseProjRuleId);
		if (rv != null) {
			return rv;
		} else {
			return new ArrayList<>();
		}
	}
	
	public List getAllInsertARTTriple(){
		List codaTripleList = new ArrayList();
		for(String baseRuleId : suggestedBaseRuleIdToInsertARTTtripleMap.keySet()){
			codaTripleList.addAll(suggestedBaseRuleIdToInsertARTTtripleMap.get(baseRuleId));
		}
		return codaTripleList;
	}
	
	//all the methods to deal with delete Triples
	public void addSuggestedDeleteTriple(String baseRuleId, CODATriple codaTriple) {
		if (!suggestedBaseRuleIdToDeleteARTTtripleMap.containsKey(baseRuleId)) {
			suggestedBaseRuleIdToDeleteARTTtripleMap.put(baseRuleId, new ArrayList());
		}
		suggestedBaseRuleIdToDeleteARTTtripleMap.get(baseRuleId).add(codaTriple);
	}

	public void addSuggestedDeleteTripleList(String baseRuleId, List codaTripleList) {
		if (!suggestedBaseRuleIdToDeleteARTTtripleMap.containsKey(baseRuleId)) {
			suggestedBaseRuleIdToDeleteARTTtripleMap.put(baseRuleId, new ArrayList());
		}
		suggestedBaseRuleIdToDeleteARTTtripleMap.get(baseRuleId).addAll(codaTripleList);
	}

	public List getDeleteARTTripleListFromBaseProjRuleId(String baseProjRuleId) {
		List rv = suggestedBaseRuleIdToDeleteARTTtripleMap.get(baseProjRuleId);
		if (rv != null) {
			return rv;
		} else {
			return new ArrayList<>();
		}
	}

	public List getAllDeleteARTTriple() {
		List codaTripleList = new ArrayList();
		for (String baseRuleId : suggestedBaseRuleIdToDeleteARTTtripleMap.keySet()) {
			codaTripleList.addAll(suggestedBaseRuleIdToDeleteARTTtripleMap.get(baseRuleId));
		}
		return codaTripleList;
	}

	/**
	 * @param selProjRules
	 *            the selected projection rules
	 * @param bindLabels
	 *            the suggestions from the Identity Resolution Component
	 * @param resSmartSuggsStruct
	 *            the suggestions form the Smart Suggestion Component
	 * @param codaFinalSuggs
	 *            the final suggestions from CODA
	 * @param ann
	 *            the annotation that triggered all these suggestions
	 */
	//public SuggOntologyCoda(SelectedProjectionRules selProjRules,
	//		CodaFinalSuggestions codaFinalSuggs, Annotation ann) {
	//	this.ann = ann;
	//	this.selProjRules = selProjRules;
	//	this.codaFinalSuggs = codaFinalSuggs;
	//}

	/**
	 * Get the selected projection rules
	 * 
	 * @return the selected projection rules
	 */
	//public SelectedProjectionRules getSelProjRules() {
	//	return selProjRules;
	//}

	/**
	 * Get the final CODA suggestions
	 * 
	 * @return the final CODA suggestions
	 */
	//public CodaFinalSuggestions getCodaFinalSuggs() {
	//	return codaFinalSuggs;
	//}

	/**
	 * Get the annotation to which all this suggestions belongs to
	 * 
	 * @return the annotation to which all this suggestions belongs to
	 */
	public Annotation getAnnotation() {
		return ann;
	}


	public Map getNodeNameToNodeAssignmentMap() throws ValueNotPresentDueToConfigurationException {
		if (nodeNameToNodeAssignmentMap == null) {
			throw new ValueNotPresentDueToConfigurationException("nodeNameToNodeAssignmentMap is not present since" +
					"the parameter addNodeAssignmentMap was false or not passed");
		}
		return nodeNameToNodeAssignmentMap;
	}

	public void addNodeAssignmen(String nodeName, NodeAssignment nodeAssignment) throws ValueNotPresentDueToConfigurationException {
		if (nodeNameToNodeAssignmentMap == null) {
			throw new ValueNotPresentDueToConfigurationException("nodeNameToNodeAssignmentMap is not present since" +
					"the parameter addNodeAssignmentMap was false or not passed");
		}
		nodeNameToNodeAssignmentMap.put(nodeName, nodeAssignment);

	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy