<commit_before>package org.flymine.ontology;

/*
 * Copyright (C) 2002-2003 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.*;

import java.io.File;
import java.io.FileWriter;
import java.io.FileReader;
import java.util.Iterator;
import java.util.Set;
import java.util.HashSet;


import org.flymine.metadata.*;
import org.flymine.util.TypeUtil;

import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntClass;

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

public class OwlFunctionalTest extends TestCase
{

    public void testRoundTrip() throws Exception {
        Model original = Model.getInstanceByName("testmodel");
        FlyMine2Owl f2o = new FlyMine2Owl();
        Model newModel = primitivesToObjectsModel(original);
        OntModel ont = f2o.process(newModel);
        File file = new File("/home/rns/ont.owl");
        ont.write(new FileWriter(file), "N3");

        OntModel fromFile = ModelFactory.createOntologyModel();
        fromFile.read(new FileReader(file), null, "N3");

        OntClass c1 = fromFile.getOntClass(original.getNameSpace() + "Company");
        assertNotNull(c1);
        assertNotNull(c1.getNameSpace());
        //assertEquals(original.getNameSpace(), c1.getNameSpace());
        Owl2FlyMine o2f = new Owl2FlyMine(original.getName(), original.getPackageName());
        assertEquals(newModel, o2f.process(ont, original.getNameSpace().toString()));
    }


    /**
     * converts primitives to corresponding java.lang objects
     * removes all primary key information
     * makes all classes interfaces
     */
    private Model primitivesToObjectsModel(Model model) throws Exception {
        Set classes = new HashSet();

        Iterator i = model.getClassDescriptors().iterator();
        while (i.hasNext()) {
            ClassDescriptor cld = (ClassDescriptor) i.next();
            Set atds = new HashSet();
            Set rfds = new HashSet();
            Set cods = new HashSet();

            Iterator j = cld.getAttributeDescriptors().iterator();
            while (j.hasNext()) {<commit_msg>got rid of write to file<commit_after>package org.flymine.ontology;

/*
 * Copyright (C) 2002-2003 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.*;

import java.io.FileReader;
import java.util.Iterator;
import java.util.Set;
import java.util.HashSet;


import org.flymine.metadata.*;
import org.flymine.util.TypeUtil;

import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntClass;

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

public class OwlFunctionalTest extends TestCase
{

    public void testRoundTrip() throws Exception {
        Model original = Model.getInstanceByName("testmodel");
        FlyMine2Owl f2o = new FlyMine2Owl();
        Model newModel = primitivesToObjectsModel(original);
        OntModel ont = f2o.process(newModel);
        Owl2FlyMine o2f = new Owl2FlyMine(original.getName(), original.getPackageName());
        assertEquals(newModel, o2f.process(ont, original.getNameSpace().toString()));
    }


    /**
     * converts primitives to corresponding java.lang objects
     * removes all primary key information
     * makes all classes interfaces
     */
    private Model primitivesToObjectsModel(Model model) throws Exception {
        Set classes = new HashSet();

        Iterator i = model.getClassDescriptors().iterator();
        while (i.hasNext()) {
            ClassDescriptor cld = (ClassDescriptor) i.next();
            Set atds = new HashSet();
            Set rfds = new HashSet();
            Set cods = new HashSet();

            Iterator j = cld.getAttributeDescriptors().iterator();
            while (j.hasNext()) {
{'fraction_non_alphanumeric': 0.10800385728061716, 'fraction_numerical': 0.009161041465766635, 'mean_word_length': 3.149, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, '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': '2014311', 'n_tokens_mistral': 1239, 'n_tokens_neox': 1201, 'n_words': 315}