<commit_before>package org.flymine.dataconversion;

/*
 * Copyright (C) 2002-2005 FlyMine
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  See the LICENSE file for more
 * information or http://www.gnu.org/copyleft/lesser.html.
 *
 */

import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Collection;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.File;
import java.io.FileWriter;

import org.intermine.xml.full.FullParser;
import org.intermine.xml.full.FullRenderer;
import org.intermine.dataconversion.DataTranslator;
import org.intermine.dataconversion.DataTranslatorTestCase;
import org.intermine.dataconversion.MockItemReader;
import org.intermine.dataconversion.MockItemWriter;
import org.intermine.dataconversion.XmlConverter;
import org.intermine.metadata.Model;

public class PsiDataTranslatorTest extends DataTranslatorTestCase {
    private String tgtNs = "http://www.flymine.org/model/genomic#";

    public PsiDataTranslatorTest(String arg) {
        super(arg);
    }
                         
    public void testTranslate() throws Exception {
        Collection srcItems = getSrcItems();

        // print out source items XML - result of running XmlConverter on PSI XML
         FileWriter writer = new FileWriter(new File("src.xml"));
         writer.write(FullRenderer.render(srcItems));
         writer.write(FullRenderer.render(srcItems));
         writer.close();

        DataTranslator translator = new PsiDataTranslator(new MockItemReader(writeItems(srcItems)),
                                                          mapping, srcModel, getTargetModel(tgtNs));
        MockItemWriter tgtIw = new MockItemWriter(new LinkedHashMap());
        translator.translate(tgtIw);


        //Use to write out the translated file if you want to make a new tgts file for testing
        FileWriter fw = new FileWriter(new File("/home/pmclaren/svn/dev/flymine/psi_tgts.xml"));
        fw.write("<items>");
        fw.write(tgtIw.getItems().toString());
        fw.write("</items>");
        fw.flush();
        fw.close();

        System.out.println(printCompareItemSets(new HashSet(getExpectedItems()), tgtIw.getItems()));

        
        assertEquals(new HashSet(getExpectedItems()), tgtIw.getItems());
    }


    protected String getModelName() {
        return "genomic";
    }

    protected String getSrcModelName() {
        return "psi";
    }

    protected Collection getExpectedItems() throws Exception {
        return FullParser.parse(getClass().getClassLoader().getResourceAsStream(
                "test/PsiDataTranslatorTest_tgt.xml"));
    }
<commit_msg>commenting out new tgt file creation<commit_after>package org.flymine.dataconversion;

/*
 * Copyright (C) 2002-2005 FlyMine
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  See the LICENSE file for more
 * information or http://www.gnu.org/copyleft/lesser.html.
 *
 */

import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Collection;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.File;
import java.io.FileWriter;

import org.intermine.xml.full.FullParser;
import org.intermine.xml.full.FullRenderer;
import org.intermine.dataconversion.DataTranslator;
import org.intermine.dataconversion.DataTranslatorTestCase;
import org.intermine.dataconversion.MockItemReader;
import org.intermine.dataconversion.MockItemWriter;
import org.intermine.dataconversion.XmlConverter;
import org.intermine.metadata.Model;

public class PsiDataTranslatorTest extends DataTranslatorTestCase {
    private String tgtNs = "http://www.flymine.org/model/genomic#";

    public PsiDataTranslatorTest(String arg) {
        super(arg);
    }
                         
    public void testTranslate() throws Exception {
        Collection srcItems = getSrcItems();

        // print out source items XML - result of running XmlConverter on PSI XML
         FileWriter writer = new FileWriter(new File("src.xml"));
         writer.write(FullRenderer.render(srcItems));
         writer.write(FullRenderer.render(srcItems));
         writer.close();

        DataTranslator translator = new PsiDataTranslator(new MockItemReader(writeItems(srcItems)),
                                                          mapping, srcModel, getTargetModel(tgtNs));
        MockItemWriter tgtIw = new MockItemWriter(new LinkedHashMap());
        translator.translate(tgtIw);


        //Use to write out the translated file if you want to make a new tgts file for testing
        /*
        FileWriter fw = new FileWriter(new File("put_your_file_name_here"));
        fw.write("<items>");
        fw.write(tgtIw.getItems().toString());
        fw.write("</items>");
        fw.flush();
        fw.close();
        */
        System.out.println(printCompareItemSets(new HashSet(getExpectedItems()), tgtIw.getItems()));

        assertEquals(new HashSet(getExpectedItems()), tgtIw.getItems());
    }


    protected String getModelName() {
        return "genomic";
    }

    protected String getSrcModelName() {
        return "psi";
    }

    protected Collection getExpectedItems() throws Exception {
        return FullParser.parse(getClass().getClassLoader().getResourceAsStream(
                "test/PsiDataTranslatorTest_tgt.xml"));
    }

{'fraction_non_alphanumeric': 0.10077240883779415, 'fraction_numerical': 0.002874079396443327, 'mean_word_length': 3.164547494390426, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 9}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6544345', 'n_tokens_mistral': 1584, 'n_tokens_neox': 1538, 'n_words': 363}