<commit_before>package org.openprovenance.prov.interop;
import java.io.File;
import java.io.IOException;
import java.util.Hashtable;
import javax.xml.bind.JAXBException;
import org.openprovenance.prov.xml.Document;
import org.openprovenance.prov.xml.ProvDeserialiser;
import org.openprovenance.prov.xml.ProvSerialiser;
import org.openprovenance.prov.xml.ProvFactory;
import org.openprovenance.prov.notation.Utility;

import  org.antlr.runtime.tree.CommonTree;

import org.openrdf.rio.RDFFormat;
import org.openprovenance.prov.dot.ProvToDot;

import org.apache.log4j.Logger;

/**
 * The interoperability framework for PROV.
 */
public class InteropFramework 
{
    
    static Logger logger = Logger.getLogger(InteropFramework.class);


    public static final String UNKNOWN = "unknown";
    public static final String PC1_NS="http://www.ipaw.info/pc1/";
    public static final String PC1_PREFIX="pc1";
    public static final String PRIM_NS="http://openprovenance.org/primitives#";
    public static final String PRIM_PREFIX="prim";
    
    final Utility u=new Utility();
    final ProvFactory pFactory=ProvFactory.getFactory();
    final private String verbose;
    final private String debug;
    final private String logfile;
    final private String infile;
    final private String outfile;
    final private String namespaces;
    public final Hashtable<ProvFormat,String> extensionMap;
    public final Hashtable<String,ProvFormat> extensionRevMap;
    public final Hashtable<ProvFormat,String> mimeTypeMap;
    public final Hashtable<String,ProvFormat> mimeTypeRevMap;
    public final Hashtable<ProvFormat,ProvFormatType> provTypeMap;


    public InteropFramework() {
        this(null, null, null, null, null, null);
    }

    
    public InteropFramework(String verbose,
                            String debug, String logfile, String infile, String outfile,
                            String namespaces) {
	this.verbose=verbose;
	this.debug=debug;
	this.logfile=logfile;
	this.infile=infile;
	this.outfile=outfile;
	this.namespaces=namespaces;
	extensionMap=new Hashtable<InteropFramework.ProvFormat, String>();
	extensionRevMap=new Hashtable<String, InteropFramework.ProvFormat>();
	mimeTypeMap=new Hashtable<InteropFramework.ProvFormat, String>();
	mimeTypeRevMap=new Hashtable<String, InteropFramework.ProvFormat>();
	provTypeMap=new Hashtable<InteropFramework.ProvFormat, InteropFramework.ProvFormatType>();

	initializeExtensionMap(extensionMap, extensionRevMap);
    }
    
    public void initializeExtensionMap(Hashtable<ProvFormat,String> extensionMap,
                                       Hashtable<String, InteropFramework.ProvFormat> extensionRevMap) {
        for (ProvFormat f: ProvFormat.values()) {
            switch (f) {
            case DOT:
                extensionMap.put(ProvFormat.DOT,"dot");
                extensionRevMap.put("dot", ProvFormat.DOT);
                extensionRevMap.put("gv", ProvFormat.DOT);
                mimeTypeMap.put(ProvFormat.DOT,"text/vnd.graphviz");
                mimeTypeRevMap.put("text/vnd.graphviz", ProvFormat.DOT);
                provTypeMap.put(ProvFormat.DOT, ProvFormatType.OUTPUT);
                break;
            case JPEG:
                extensionMap.put(ProvFormat.JPEG,"jpg");
                extensionRevMap.put("jpeg", ProvFormat.JPEG);
                extensionRevMap.put("jpg", ProvFormat.JPEG);
                mimeTypeMap.put(ProvFormat.JPEG,"image/jpeg");
                mimeTypeRevMap.put("image/jpeg", ProvFormat.JPEG);
                provTypeMap.put(ProvFormat.DOT, ProvFormatType.OUTPUT);
                break;
            case JSON:
                extensionMap.put(ProvFormat.JSON,"json");
                extensionRevMap.put("json", ProvFormat.JSON);
                mimeTypeMap.put(ProvFormat.JSON,"application/json");
                mimeTypeRevMap.put("application/json", ProvFormat.JSON);
                provTypeMap.put(ProvFormat.DOT, ProvFormatType.INPUTOUTPUT);
                break;
            case PDF:
                extensionMap.put(ProvFormat.PDF,"pdf");
                extensionRevMap.put("pdf", ProvFormat.PDF);
                mimeTypeMap.put(ProvFormat.PDF,"application/pdf");
                mimeTypeRevMap.put("application/pdf", ProvFormat.PDF);
                provTypeMap.put(ProvFormat.DOT, ProvFormatType.OUTPUT);
                break;
            case PROVN:
                extensionMap.put(ProvFormat.PROVN,"provn");
                extensionRevMap.put("provn", ProvFormat.PROVN);
                extensionRevMap.put("pn", ProvFormat.PROVN);
                extensionRevMap.put("asn", ProvFormat.PROVN);
                extensionRevMap.put("prov-asn", ProvFormat.PROVN);
                mimeTypeMap.put(ProvFormat.PROVN,"text/provenance-notation");
                mimeTypeRevMap.put("text/provenance-notation", ProvFormat.PROVN);
                provTypeMap.put(ProvFormat.DOT, ProvFormatType.INPUTOUTPUT);
                break;
            case RDFXML:
                extensionMap.put(ProvFormat.RDFXML,"rdf");
                extensionRevMap.put("rdf", ProvFormat.RDFXML);
                mimeTypeMap.put(ProvFormat.RDFXML,"application/rdf+xml");
                mimeTypeRevMap.put("application/rdf+xml", ProvFormat.RDFXML);
                provTypeMap.put(ProvFormat.DOT, ProvFormatType.INPUTOUTPUT);
                break;
            case SVG:
                extensionMap.put(ProvFormat.SVG,"svg");
                extensionRevMap.put("svg", ProvFormat.SVG);
                mimeTypeMap.put(ProvFormat.SVG,"image/svg+xml");
                mimeTypeRevMap.put("image/svg+xml", ProvFormat.SVG);
                provTypeMap.put(ProvFormat.DOT, ProvFormatType.OUTPUT);
                break;
            case TRIG:
                extensionMap.put(ProvFormat.TRIG,"trig");
                extensionRevMap.put("trig", ProvFormat.TRIG);
                mimeTypeMap.put(ProvFormat.TRIG, "application/x-trig");
                mimeTypeRevMap.put("application/x-trig", ProvFormat.TRIG);
                provTypeMap.put(ProvFormat.DOT, ProvFormatType.INPUTOUTPUT);
                break;
            case TURTLE:
                extensionMap.put(ProvFormat.TURTLE,"ttl");
                extensionRevMap.put("ttl", ProvFormat.TURTLE);    
                mimeTypeMap.put(ProvFormat.TURTLE,"text/turtle");
                mimeTypeRevMap.put("text/turtle", ProvFormat.TURTLE);
                provTypeMap.put(ProvFormat.DOT, ProvFormatType.INPUTOUTPUT);
                break;
            case XML:
                extensionMap.put(ProvFormat.XML,"provx");
                extensionRevMap.put("provx", ProvFormat.XML);             
                extensionRevMap.put("xml", ProvFormat.XML);    
                mimeTypeMap.put(ProvFormat.XML,"text/xml");
                mimeTypeRevMap.put("text/xml", ProvFormat.XML);
                provTypeMap.put(ProvFormat.DOT, ProvFormatType.INPUTOUTPUT);
                break;
            default:
                break;
       
            }
        }
        
    }
    
    public String getExtension(ProvFormat format) {
        String extension=UNKNOWN;
        if (format!=null) {
            extension=extensionMap.get(format);
        }
        return extension;<commit_msg>Put the correct formats into provTypeMap.<commit_after>package org.openprovenance.prov.interop;
import java.io.File;
import java.io.IOException;
import java.util.Hashtable;
import javax.xml.bind.JAXBException;
import org.openprovenance.prov.xml.Document;
import org.openprovenance.prov.xml.ProvDeserialiser;
import org.openprovenance.prov.xml.ProvSerialiser;
import org.openprovenance.prov.xml.ProvFactory;
import org.openprovenance.prov.notation.Utility;

import  org.antlr.runtime.tree.CommonTree;

import org.openrdf.rio.RDFFormat;
import org.openprovenance.prov.dot.ProvToDot;

import org.apache.log4j.Logger;

/**
 * The interoperability framework for PROV.
 */
public class InteropFramework 
{
    
    static Logger logger = Logger.getLogger(InteropFramework.class);


    public static final String UNKNOWN = "unknown";
    public static final String PC1_NS="http://www.ipaw.info/pc1/";
    public static final String PC1_PREFIX="pc1";
    public static final String PRIM_NS="http://openprovenance.org/primitives#";
    public static final String PRIM_PREFIX="prim";
    
    final Utility u=new Utility();
    final ProvFactory pFactory=ProvFactory.getFactory();
    final private String verbose;
    final private String debug;
    final private String logfile;
    final private String infile;
    final private String outfile;
    final private String namespaces;
    public final Hashtable<ProvFormat,String> extensionMap;
    public final Hashtable<String,ProvFormat> extensionRevMap;
    public final Hashtable<ProvFormat,String> mimeTypeMap;
    public final Hashtable<String,ProvFormat> mimeTypeRevMap;
    public final Hashtable<ProvFormat,ProvFormatType> provTypeMap;


    public InteropFramework() {
        this(null, null, null, null, null, null);
    }

    
    public InteropFramework(String verbose,
                            String debug, String logfile, String infile, String outfile,
                            String namespaces) {
	this.verbose=verbose;
	this.debug=debug;
	this.logfile=logfile;
	this.infile=infile;
	this.outfile=outfile;
	this.namespaces=namespaces;
	extensionMap=new Hashtable<InteropFramework.ProvFormat, String>();
	extensionRevMap=new Hashtable<String, InteropFramework.ProvFormat>();
	mimeTypeMap=new Hashtable<InteropFramework.ProvFormat, String>();
	mimeTypeRevMap=new Hashtable<String, InteropFramework.ProvFormat>();
	provTypeMap=new Hashtable<InteropFramework.ProvFormat, InteropFramework.ProvFormatType>();

	initializeExtensionMap(extensionMap, extensionRevMap);
    }
    
    public void initializeExtensionMap(Hashtable<ProvFormat,String> extensionMap,
                                       Hashtable<String, InteropFramework.ProvFormat> extensionRevMap) {
        for (ProvFormat f: ProvFormat.values()) {
            switch (f) {
            case DOT:
                extensionMap.put(ProvFormat.DOT,"dot");
                extensionRevMap.put("dot", ProvFormat.DOT);
                extensionRevMap.put("gv", ProvFormat.DOT);
                mimeTypeMap.put(ProvFormat.DOT,"text/vnd.graphviz");
                mimeTypeRevMap.put("text/vnd.graphviz", ProvFormat.DOT);
                provTypeMap.put(ProvFormat.DOT, ProvFormatType.OUTPUT);
                break;
            case JPEG:
                extensionMap.put(ProvFormat.JPEG,"jpg");
                extensionRevMap.put("jpeg", ProvFormat.JPEG);
                extensionRevMap.put("jpg", ProvFormat.JPEG);
                mimeTypeMap.put(ProvFormat.JPEG,"image/jpeg");
                mimeTypeRevMap.put("image/jpeg", ProvFormat.JPEG);
                provTypeMap.put(ProvFormat.JPEG, ProvFormatType.OUTPUT);
                break;
            case JSON:
                extensionMap.put(ProvFormat.JSON,"json");
                extensionRevMap.put("json", ProvFormat.JSON);
                mimeTypeMap.put(ProvFormat.JSON,"application/json");
                mimeTypeRevMap.put("application/json", ProvFormat.JSON);
                provTypeMap.put(ProvFormat.JSON, ProvFormatType.INPUTOUTPUT);
                break;
            case PDF:
                extensionMap.put(ProvFormat.PDF,"pdf");
                extensionRevMap.put("pdf", ProvFormat.PDF);
                mimeTypeMap.put(ProvFormat.PDF,"application/pdf");
                mimeTypeRevMap.put("application/pdf", ProvFormat.PDF);
                provTypeMap.put(ProvFormat.PDF, ProvFormatType.OUTPUT);
                break;
            case PROVN:
                extensionMap.put(ProvFormat.PROVN,"provn");
                extensionRevMap.put("provn", ProvFormat.PROVN);
                extensionRevMap.put("pn", ProvFormat.PROVN);
                extensionRevMap.put("asn", ProvFormat.PROVN);
                extensionRevMap.put("prov-asn", ProvFormat.PROVN);
                mimeTypeMap.put(ProvFormat.PROVN,"text/provenance-notation");
                mimeTypeRevMap.put("text/provenance-notation", ProvFormat.PROVN);
                provTypeMap.put(ProvFormat.PROVN, ProvFormatType.INPUTOUTPUT);
                break;
            case RDFXML:
                extensionMap.put(ProvFormat.RDFXML,"rdf");
                extensionRevMap.put("rdf", ProvFormat.RDFXML);
                mimeTypeMap.put(ProvFormat.RDFXML,"application/rdf+xml");
                mimeTypeRevMap.put("application/rdf+xml", ProvFormat.RDFXML);
                provTypeMap.put(ProvFormat.RDFXML, ProvFormatType.INPUTOUTPUT);
                break;
            case SVG:
                extensionMap.put(ProvFormat.SVG,"svg");
                extensionRevMap.put("svg", ProvFormat.SVG);
                mimeTypeMap.put(ProvFormat.SVG,"image/svg+xml");
                mimeTypeRevMap.put("image/svg+xml", ProvFormat.SVG);
                provTypeMap.put(ProvFormat.SVG, ProvFormatType.OUTPUT);
                break;
            case TRIG:
                extensionMap.put(ProvFormat.TRIG,"trig");
                extensionRevMap.put("trig", ProvFormat.TRIG);
                mimeTypeMap.put(ProvFormat.TRIG, "application/x-trig");
                mimeTypeRevMap.put("application/x-trig", ProvFormat.TRIG);
                provTypeMap.put(ProvFormat.TRIG, ProvFormatType.INPUTOUTPUT);
                break;
            case TURTLE:
                extensionMap.put(ProvFormat.TURTLE,"ttl");
                extensionRevMap.put("ttl", ProvFormat.TURTLE);    
                mimeTypeMap.put(ProvFormat.TURTLE,"text/turtle");
                mimeTypeRevMap.put("text/turtle", ProvFormat.TURTLE);
                provTypeMap.put(ProvFormat.TURTLE, ProvFormatType.INPUTOUTPUT);
                break;
            case XML:
                extensionMap.put(ProvFormat.XML,"provx");
                extensionRevMap.put("provx", ProvFormat.XML);             
                extensionRevMap.put("xml", ProvFormat.XML);    
                mimeTypeMap.put(ProvFormat.XML,"text/xml");
                mimeTypeRevMap.put("text/xml", ProvFormat.XML);
                provTypeMap.put(ProvFormat.XML, ProvFormatType.INPUTOUTPUT);
                break;
            default:
                break;
       
            }
        }
        
    }
    
    public String getExtension(ProvFormat format) {
        String extension=UNKNOWN;
        if (format!=null) {
            extension=extensionMap.get(format);
        }
        return extension;
{'fraction_non_alphanumeric': 0.10449399656946827, 'fraction_numerical': 0.0006861063464837049, 'mean_word_length': 2.4032220406257294, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 24}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3439882', 'n_tokens_mistral': 4232, 'n_tokens_neox': 4027, 'n_words': 624}