<commit_before>package it.unibz.krdb.obda.io;

import java.util.Map;

public abstract class AbstractPrefixManager implements PrefixManager {

	public String getShortForm(String uri) {
		return getShortForm(uri, false);
	}
	
	public String getShortForm(String uri, boolean insideQuotes) {
		final Map<String, String> prefixMap = getPrefixMap();
		String shortUri = uri;
		for (String prefixUriDefinition : prefixMap.values()) {
			if (uri.contains(prefixUriDefinition)) {
				String prefix = getPrefix(prefixUriDefinition);
				if (insideQuotes) {
					prefix = String.format("&%s;", removeColon(prefix));
				}
				// Replace the URI with the corresponding prefix.
				shortUri = uri.replace(prefixUriDefinition, prefix);
				
				// Clean the URI string from <> signs, if exist
				if (shortUri.contains("<") && shortUri.contains(">")) {
					shortUri = shortUri.replace("<", "").replace(">", "");
				}
				return shortUri;
			}
		}
		return shortUri;
	}
	
	public String getDefaultPrefix() {
		return getPrefixMap().get(DEFAULT_PREFIX);
	}
		
	/**
	 * A utility method to ensure a proper naming for prefix URI
	 */
	protected String getProperPrefixURI(String prefixUri) {<commit_msg>Fix the URI shorten method in the case there are two or more prefix  definitions with overlapped strings. For example:<commit_after>package it.unibz.krdb.obda.io;

import java.util.Map;

public abstract class AbstractPrefixManager implements PrefixManager {

	public String getShortForm(String uri) {
		return getShortForm(uri, false);
	}
	
	public String getShortForm(String uri, boolean insideQuotes) {
		final Map<String, String> prefixMap = getPrefixMap();
		
		/* Clean the URI string from <...> signs, if they exist.
		 * <http://www.example.org/library#Book> --> http://www.example.org/library#Book
		 */
		if (uri.contains("<") && uri.contains(">")) {
			uri = uri.replace("<", "").replace(">", "");
		}
		
		// Initial value for the short URI
		String shortUri = uri;
		
		String subUri = "";
		if (uri.contains("#")) {
			/* 
			 * Obtain the URI definition that contains a hash sign
			 * http://www.example.org/library#Book --> http://www.example.org/library#
			 */
			subUri = uri.substring(0, uri.lastIndexOf("#")+1);
		} else {
			/* 
			 * Obtain the URI definition that contains a slash sign
			 * http://www.example.org/library/Book --> http://www.example.org/library/
			 */
			subUri = uri.substring(0, uri.lastIndexOf("/")+1);
		}
		
		// Check if the URI string has a matched prefix
		for (String prefixUriDefinition : prefixMap.values()) {
			if (subUri.equals(prefixUriDefinition)) {
				String prefix = getPrefix(prefixUriDefinition);
				if (insideQuotes) {
					prefix = String.format("&%s;", removeColon(prefix));
				}
				// Replace the URI with the corresponding prefix.
				shortUri = uri.replace(prefixUriDefinition, prefix);
				
				return shortUri;
			}
		}
		return shortUri;
	}
	
	public String getDefaultPrefix() {
		return getPrefixMap().get(DEFAULT_PREFIX);
	}
		
	/**
	 * A utility method to ensure a proper naming for prefix URI
	 */
	protected String getProperPrefixURI(String prefixUri) {
{'fraction_non_alphanumeric': 0.13012820512820514, 'fraction_numerical': 0.001282051282051282, 'mean_word_length': 3.5363372093023258, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, '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': '6724189', 'n_tokens_mistral': 1077, 'n_tokens_neox': 915, 'n_words': 256}