<commit_before>package org.flymine.dataconversion;

/*
 * Copyright (C) 2002-2004 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 junit.framework.TestCase;

import java.util.Map;
import java.util.HashMap;
import java.util.Set;
import java.util.HashSet;
import java.util.List;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.LinkedHashMap;
import java.util.Collection;
import java.util.Arrays;
import java.io.InputStreamReader;
import java.io.FileWriter;
import java.io.File;
import java.io.BufferedReader;

import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.model.ModelFactory;

import org.intermine.xml.full.FullParser;
import org.intermine.xml.full.FullRenderer;
import org.intermine.xml.full.Attribute;
import org.intermine.xml.full.Item;
import org.intermine.xml.full.Reference;
import org.intermine.xml.full.ReferenceList;
import org.intermine.dataconversion.DataTranslator;
import org.intermine.dataconversion.DataTranslatorTestCase;
import org.intermine.dataconversion.MockItemReader;
import org.intermine.dataconversion.MockItemWriter;

/**
 * Test for translating MAGE data in fulldata Item format conforming to a source OWL definition
 * to fulldata Item format conforming to InterMine OWL definition.
 *
 * @author <NAME>
 * @author <NAME>
 */

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

    public void setUp() throws Exception {
        super.setUp();
    }


    public void testTranslate() throws Exception {
        Collection srcItems = getSrcItems();
        FileWriter writerSrc = new FileWriter(new File("src_items.xml"));
        writerSrc.write(FullRenderer.render(srcItems));
        writerSrc.close();


        Map itemMap = writeItems(srcItems);
        DataTranslator translator = new MageDataTranslator(new MockItemReader(itemMap),
                                                           getOwlModel(), tgtNs);

        MockItemWriter tgtIw = new MockItemWriter(new LinkedHashMap());
        translator.translate(tgtIw);

        FileWriter writer = new FileWriter(new File("exptmp"));
        writer.write(FullRenderer.render(tgtIw.getItems()));
        writer.close();

        //assertEquals(new HashSet(expectedItems), tgtIw.getItems());

    }

    public void testCreateAuthors() {

        Item srcItem = createItem(ns + "BibliographicReference", "0_0", "");
        srcItem.addAttribute(new Attribute("authors", " <NAME>; FlyChip Facility"));

        Item exp1 = createItem(tgtNs + "Author", "-1_1", "");
        exp1.addAttribute(new Attribute("name", "<NAME>"));
        Item exp2 = createItem(tgtNs + "Author", "-1_2", "");
        exp2.addAttribute(new Attribute("name", "FlyChip Facility"));

        Set expected = new HashSet(Arrays.asList(new Object[] {exp1, exp2}));

        MageDataTranslator translator = new MageDataTranslator(new MockItemReader(new HashMap()),
                                                           getOwlModel(), tgtNs);
        assertEquals(expected, translator.createAuthors(srcItem));
    }

    public void testSetReporterLocationCoords() throws Exception{
        Item srcItem = createItem(ns + "FeatureReporterMap", "6_28", "");
        srcItem.addCollection(new ReferenceList("featureInformationSources", new ArrayList(Arrays.asList(new Object[]{"7_29"}))));

        Item srcItem2=createItem(ns + "FeatureInformation", "7_29", "");
        srcItem2. addReference(new Reference("feature", "8_30"));
<commit_msg>stopped output of temporary files<commit_after>package org.flymine.dataconversion;

/*
 * Copyright (C) 2002-2004 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 junit.framework.TestCase;

import java.util.Map;
import java.util.HashMap;
import java.util.Set;
import java.util.HashSet;
import java.util.List;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.LinkedHashMap;
import java.util.Collection;
import java.util.Arrays;
import java.io.InputStreamReader;
import java.io.FileWriter;
import java.io.File;
import java.io.BufferedReader;

import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.model.ModelFactory;

import org.intermine.xml.full.FullParser;
import org.intermine.xml.full.FullRenderer;
import org.intermine.xml.full.Attribute;
import org.intermine.xml.full.Item;
import org.intermine.xml.full.Reference;
import org.intermine.xml.full.ReferenceList;
import org.intermine.dataconversion.DataTranslator;
import org.intermine.dataconversion.DataTranslatorTestCase;
import org.intermine.dataconversion.MockItemReader;
import org.intermine.dataconversion.MockItemWriter;

/**
 * Test for translating MAGE data in fulldata Item format conforming to a source OWL definition
 * to fulldata Item format conforming to InterMine OWL definition.
 *
 * @author <NAME>
 * @author <NAME>
 */

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

    public void setUp() throws Exception {
        super.setUp();
    }


    public void testTranslate() throws Exception {
        Collection srcItems = getSrcItems();
        //FileWriter writerSrc = new FileWriter(new File("src_items.xml"));
        //writerSrc.write(FullRenderer.render(srcItems));
        //writerSrc.close();


        Map itemMap = writeItems(srcItems);
        DataTranslator translator = new MageDataTranslator(new MockItemReader(itemMap),
                                                           getOwlModel(), tgtNs);

        MockItemWriter tgtIw = new MockItemWriter(new LinkedHashMap());
        translator.translate(tgtIw);

        //FileWriter writer = new FileWriter(new File("exptmp"));
        //writer.write(FullRenderer.render(tgtIw.getItems()));
        //writer.close();

        //assertEquals(new HashSet(expectedItems), tgtIw.getItems());

    }

    public void testCreateAuthors() {

        Item srcItem = createItem(ns + "BibliographicReference", "0_0", "");
        srcItem.addAttribute(new Attribute("authors", " <NAME>; FlyChip Facility"));

        Item exp1 = createItem(tgtNs + "Author", "-1_1", "");
        exp1.addAttribute(new Attribute("name", "<NAME>"));
        Item exp2 = createItem(tgtNs + "Author", "-1_2", "");
        exp2.addAttribute(new Attribute("name", "FlyChip Facility"));

        Set expected = new HashSet(Arrays.asList(new Object[] {exp1, exp2}));

        MageDataTranslator translator = new MageDataTranslator(new MockItemReader(new HashMap()),
                                                           getOwlModel(), tgtNs);
        assertEquals(expected, translator.createAuthors(srcItem));
    }

    public void testSetReporterLocationCoords() throws Exception{
        Item srcItem = createItem(ns + "FeatureReporterMap", "6_28", "");
        srcItem.addCollection(new ReferenceList("featureInformationSources", new ArrayList(Arrays.asList(new Object[]{"7_29"}))));

        Item srcItem2=createItem(ns + "FeatureInformation", "7_29", "");
        srcItem2. addReference(new Reference("feature", "8_30"));

{'fraction_non_alphanumeric': 0.1171569903670919, 'fraction_numerical': 0.008851861494402499, 'mean_word_length': 3.5759380583680764, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 14}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '20794', 'n_tokens_mistral': 2274, 'n_tokens_neox': 2207, 'n_words': 508}