<commit_before><commit_msg>Added an interface so that the application can use either the EntityIndexer (that reads the xml files directly) or the EntityCollection that uses xquery. Added unique identifiers that can be used in preference to the url.<commit_after>package nl.mpi.kinnate.uniqueidentifiers;

import java.io.File;
import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import nl.mpi.arbil.GuiHelper;
import nl.mpi.arbil.clarin.CmdiComponentBuilder;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;

/**
 *  Document   : LocalIdentifier
 *  Created on : Mar 22, 2011, 2:25:22 PM
 *  Author     : <NAME>
 */
public class LocalIdentifier {

    public String getUniqueIdentifier(File entityFile) {
        StringBuilder hexString = new StringBuilder();
        try {
            MessageDigest digest = MessageDigest.getInstance("MD5");
            digest.update(entityFile.toString().getBytes());
            byte[] md5sum = digest.digest();
            for (int byteCounter = 0; byteCounter < md5sum.length; ++byteCounter) {
                hexString.append(Integer.toHexString(0x0100 + (md5sum[byteCounter] & 0x00FF)).substring(1));
            }
        } catch (NoSuchAlgorithmException algorithmException) {
            GuiHelper.linorgBugCatcher.logError(algorithmException);
        }
        return hexString.toString();
    }

    public String setLocalIdentifier(File entityFile) {
        String localIdentifier = getUniqueIdentifier(entityFile);
        try {
            Document metadataDom = new CmdiComponentBuilder().getDocument(entityFile.toURI());
            // add a unique identifier to the entity node
            Element localIdentifierElement = metadataDom.createElement("LocalIdentifier");
            localIdentifierElement.setTextContent(localIdentifier);
            Node uniqueIdentifierNode = org.apache.xpath.XPathAPI.selectSingleNode(metadataDom, "/Kinnate/Entity/UniqueIdentifier");
            uniqueIdentifierNode.appendChild(localIdentifierElement);
            new CmdiComponentBuilder().savePrettyFormatting(metadataDom, entityFile);
        } catch (DOMException exception) {
            GuiHelper.linorgBugCatcher.logError(exception);
        } catch (TransformerException exception) {
            GuiHelper.linorgBugCatcher.logError(exception);
        } catch (IOException exception) {
            GuiHelper.linorgBugCatcher.logError(exception);
        } catch (ParserConfigurationException exception) {
            GuiHelper.linorgBugCatcher.logError(exception);
        } catch (SAXException exception) {
            GuiHelper.linorgBugCatcher.logError(exception);
        }
        return localIdentifier;
    }
}
{'fraction_non_alphanumeric': 0.08879781420765027, 'fraction_numerical': 0.009904371584699454, 'mean_word_length': 3.411144578313253, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '5217924', 'n_tokens_mistral': 790, 'n_tokens_neox': 751, 'n_words': 163}