<commit_before>package edu.georgetown.library.fileAnalyzer.filetest.iiif;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;

import java.util.TreeSet;

import javax.xml.xpath.XPath;

import org.apache.tika.exception.TikaException;
import org.json.JSONArray;
import org.json.JSONObject;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;

import edu.georgetown.library.fileAnalyzer.filetest.iiif.IIIFEnums.DefaultDimensions;
import edu.georgetown.library.fileAnalyzer.filetest.iiif.IIIFEnums.IIIFArray;
import edu.georgetown.library.fileAnalyzer.filetest.iiif.IIIFEnums.IIIFLookupEnum;
import edu.georgetown.library.fileAnalyzer.filetest.iiif.IIIFEnums.IIIFStandardProp;
import edu.georgetown.library.fileAnalyzer.filetest.iiif.IIIFEnums.IIIFMetadataProp;
import edu.georgetown.library.fileAnalyzer.filetest.iiif.IIIFEnums.IIIFType;
import edu.georgetown.library.fileAnalyzer.util.XMLUtil;

public class IIIFManifest extends IIIFJSONWrapper {
        private File file;
        protected IIIFJSONWrapper seq;
        protected XPath xp;
        
        protected HashMap<File,JSONObject> ranges = new HashMap<>();
        
        TreeSet<IIIFCanvasWrapper> orderedCanvases = new TreeSet<>();
        //TODO: store range ref inside of canvas
        HashMap<String,RangePath> parentRangeForCanvas = new HashMap<>();
        
        RangePath top;
        protected MetadataInputFile inputMetadata;
        ManifestGeneratePropFile manifestGen;
        private boolean isCollectionManifest = false;
        private String manifestRoot = "";

       
        public IIIFManifest(MetadataInputFile inputMetadata, ManifestGeneratePropFile manifestGen) throws IOException, InputFileException {
                this(inputMetadata, manifestGen, manifestGen.getManifestOutputFile(), manifestGen.getCreateCollectionManifest());
        }      

        public IIIFManifest(MetadataInputFile inputMetadata, ManifestGeneratePropFile manifestGen, File compFile) throws IOException, InputFileException {
                this(inputMetadata, manifestGen, compFile, false);
        }

        public IIIFManifest(MetadataInputFile inputMetadata, ManifestGeneratePropFile manifestGen, File compFile, boolean isCollectionManifest) throws IOException, InputFileException {
                super(manifestGen.getIIIFRoot());
                this.manifestGen = manifestGen;
                this.manifestRoot = manifestGen.getManifestRoot();
                file = compFile;
                checkManifestFile(file);
                this.inputMetadata = inputMetadata;
                xp = XMLUtil.xf.newXPath();
                this.isCollectionManifest = isCollectionManifest;
                if (!isCollectionManifest) {
                        seq = addSequence();
                }
        }      

        /*
         * Call this after the proper translator object has been set
         */
        public void init(File root) {
                setProperty(IIIFType.typeManifest, IIIFStandardProp.context);
                setProperty(isCollectionManifest ? IIIFType.typeCollection : IIIFType.typeManifest);
                
                String def = "";
                def = manifestGen.getProperty(IIIFLookupEnum.Title.getLookup());
                String label = inputMetadata.getValue(IIIFLookupEnum.Title.getLookup(), def);
                if (label.isEmpty()) {
                        label = "--";
                }
                setProperty(IIIFType.typeManifest, IIIFStandardProp.label, label); 
                def = manifestGen.getProperty(IIIFLookupEnum.DateCreated.getLookup());
                setProperty(IIIFType.typeManifest, IIIFStandardProp.attribution, inputMetadata.getValue(IIIFLookupEnum.DateCreated.getLookup(), def));
                def = manifestGen.getProperty(IIIFLookupEnum.Creator.getLookup());
                setProperty(IIIFType.typeManifest, IIIFStandardProp.attribution, inputMetadata.getValue(IIIFLookupEnum.Creator.getLookup(), def));
                def = manifestGen.getProperty(IIIFLookupEnum.Description.getLookup());
                setProperty(IIIFType.typeManifest, IIIFStandardProp.attribution, inputMetadata.getValue(IIIFLookupEnum.Description.getLookup(), def));<commit_msg>no label<commit_after>package edu.georgetown.library.fileAnalyzer.filetest.iiif;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;

import java.util.TreeSet;

import javax.xml.xpath.XPath;

import org.apache.tika.exception.TikaException;
import org.json.JSONArray;
import org.json.JSONObject;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;

import edu.georgetown.library.fileAnalyzer.filetest.iiif.IIIFEnums.DefaultDimensions;
import edu.georgetown.library.fileAnalyzer.filetest.iiif.IIIFEnums.IIIFArray;
import edu.georgetown.library.fileAnalyzer.filetest.iiif.IIIFEnums.IIIFLookupEnum;
import edu.georgetown.library.fileAnalyzer.filetest.iiif.IIIFEnums.IIIFStandardProp;
import edu.georgetown.library.fileAnalyzer.filetest.iiif.IIIFEnums.IIIFMetadataProp;
import edu.georgetown.library.fileAnalyzer.filetest.iiif.IIIFEnums.IIIFType;
import edu.georgetown.library.fileAnalyzer.util.XMLUtil;

public class IIIFManifest extends IIIFJSONWrapper {
        private File file;
        protected IIIFJSONWrapper seq;
        protected XPath xp;
        
        protected HashMap<File,JSONObject> ranges = new HashMap<>();
        
        TreeSet<IIIFCanvasWrapper> orderedCanvases = new TreeSet<>();
        //TODO: store range ref inside of canvas
        HashMap<String,RangePath> parentRangeForCanvas = new HashMap<>();
        
        RangePath top;
        protected MetadataInputFile inputMetadata;
        ManifestGeneratePropFile manifestGen;
        private boolean isCollectionManifest = false;
        private String manifestRoot = "";

       
        public IIIFManifest(MetadataInputFile inputMetadata, ManifestGeneratePropFile manifestGen) throws IOException, InputFileException {
                this(inputMetadata, manifestGen, manifestGen.getManifestOutputFile(), manifestGen.getCreateCollectionManifest());
        }      

        public IIIFManifest(MetadataInputFile inputMetadata, ManifestGeneratePropFile manifestGen, File compFile) throws IOException, InputFileException {
                this(inputMetadata, manifestGen, compFile, false);
        }

        public IIIFManifest(MetadataInputFile inputMetadata, ManifestGeneratePropFile manifestGen, File compFile, boolean isCollectionManifest) throws IOException, InputFileException {
                super(manifestGen.getIIIFRoot());
                this.manifestGen = manifestGen;
                this.manifestRoot = manifestGen.getManifestRoot();
                file = compFile;
                checkManifestFile(file);
                this.inputMetadata = inputMetadata;
                xp = XMLUtil.xf.newXPath();
                this.isCollectionManifest = isCollectionManifest;
                if (!isCollectionManifest) {
                        seq = addSequence();
                }
        }      

        /*
         * Call this after the proper translator object has been set
         */
        public void init(File root) {
                setProperty(IIIFType.typeManifest, IIIFStandardProp.context);
                setProperty(isCollectionManifest ? IIIFType.typeCollection : IIIFType.typeManifest);
                
                String def = "";
                def = manifestGen.getProperty(IIIFLookupEnum.Title.getLookup());
                String label = inputMetadata.getValue(IIIFLookupEnum.Title.getLookup(), def);
                if (label.isEmpty()) {
                        label = "(no label)";
                }
                setProperty(IIIFType.typeManifest, IIIFStandardProp.label, label); 
                def = manifestGen.getProperty(IIIFLookupEnum.DateCreated.getLookup());
                setProperty(IIIFType.typeManifest, IIIFStandardProp.attribution, inputMetadata.getValue(IIIFLookupEnum.DateCreated.getLookup(), def));
                def = manifestGen.getProperty(IIIFLookupEnum.Creator.getLookup());
                setProperty(IIIFType.typeManifest, IIIFStandardProp.attribution, inputMetadata.getValue(IIIFLookupEnum.Creator.getLookup(), def));
                def = manifestGen.getProperty(IIIFLookupEnum.Description.getLookup());
                setProperty(IIIFType.typeManifest, IIIFStandardProp.attribution, inputMetadata.getValue(IIIFLookupEnum.Description.getLookup(), def));
{'fraction_non_alphanumeric': 0.08402574605032183, 'fraction_numerical': 0.00023405500292568755, 'mean_word_length': 2.954650624710782, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '6443436', 'n_tokens_mistral': 2289, 'n_tokens_neox': 2208, 'n_words': 388}