<commit_before>package com.github.anno4j.persistence;

import com.github.anno4j.model.Annotation;
import com.github.anno4j.model.Body;
import com.github.anno4j.model.Target;
import com.github.anno4j.model.namespaces.DCTYPES;
import com.github.anno4j.model.namespaces.RDF;
import com.github.anno4j.persistence.impl.ObjectParser;
import org.junit.Test;
import org.openrdf.annotations.Iri;
import org.openrdf.repository.RepositoryException;
import org.openrdf.repository.config.RepositoryConfigException;
import org.openrdf.rio.RDFFormat;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

import static org.junit.Assert.assertEquals;

/**
 * Testsuite testing the {@link ObjectParser} class.
 */
public class ObjectParserTest {

    @Test
    public void testJSONLD() {

        try {
            URL url = new URL("http://example.com/");

            ObjectParser objectParser = new ObjectParser();
            List<Annotation> annotations = objectParser.parse(JSONLD, url, RDFFormat.JSONLD);

            for(Annotation anno : annotations) {
                System.out.println(anno.toString());
            }

            assertEquals(1, annotations.size());

            objectParser.shutdown();
        } catch (RepositoryException | MalformedURLException | RepositoryConfigException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void testTurtle() {
        try {
            URL url = new URL("http://example.com/");

            ObjectParser objectParser = new ObjectParser();
            List<Annotation> annotations = objectParser.parse(TURTLE, url, RDFFormat.TURTLE);

            for(Annotation anno : annotations) {
                System.out.println(anno.toString());
            }

            assertEquals(1, annotations.size());

            objectParser.shutdown();
        } catch (IOException | RepositoryException | RepositoryConfigException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void testMultipleTurtle() {
        try {
            URL url = new URL("http://example.com/");

            ObjectParser objectParser = new ObjectParser();

            objectParser.parse(TURTLE, url, RDFFormat.TURTLE);
            objectParser.parse(TURTLE2, url, RDFFormat.TURTLE);
            List<Annotation> annotations = objectParser.parse(TURTLE3, url, RDFFormat.TURTLE);

            assertEquals(3, annotations.size());

            for(Annotation anno : annotations) {
                System.out.println(anno.toString());
            }

            objectParser.shutdown();
        } catch (IOException | RepositoryException | RepositoryConfigException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void testMultipleInOneTurtle() {
        try {
            URL url = new URL("http://example.com/");

            ObjectParser objectParser = new ObjectParser();
            List<Annotation> annotations = objectParser.parse(TURTLE_MULTIPLE, url, RDFFormat.TURTLE);

            assertEquals(3, annotations.size());

            for(Annotation anno : annotations) {
                System.out.println(anno.toString());
            }

            objectParser.shutdown();
        } catch (IOException | RepositoryException | RepositoryConfigException e) {
            e.printStackTrace();
        }
    }

    /**
     * Inner class to represent a sound media item.
     */
    @Iri(DCTYPES.SOUND)
    public static class Sound extends Body {

        public Sound() {}

        @Iri(RDF.VALUE)
        private String value;

        /**
         * Sets new value.
         *
         * @param value New value of value.
         */
        public void setValue(String value) {
            this.value = value;
        }

        /**
         * Gets value.
         *
         * @return Value of value.
         */
        public String getValue() {
            return value;
        }

        @Override
        public String toString() {
            return "Sound{" +
                    "value='" + value + '\'' +
                    '}';
        }
    }

    /**
     * Inner class to represent an image media file as body.
     */
    @Iri(DCTYPES.IMAGE)
    public static class Image extends Target {

        public Image() {}
    }

    private final static String TURTLE = "@prefix oa: <http://www.w3.org/ns/oa#> ." +
            "@prefix ex: <http://www.example.com/ns#> ." +
            "@prefix dctypes: <http://purl.org/dc/dcmitype/> ." +
            "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> ." +

            "ex:anno1 a oa:Annotation ;" +
            "   oa:hasBody ex:body1 ;" +
            "   oa:hasTarget ex:target1 ." +

            "ex:body1 a dctypes:Sound ;" +
            "   rdf:value \"somevalue\" ." +
            "ex:target1 a dctypes:Image .";

    private final static String TURTLE2 = "@prefix oa: <http://www.w3.org/ns/oa#> ." +
            "@prefix ex: <http://www.example.com/ns#> ." +
            "@prefix dctypes: <http://purl.org/dc/dcmitype/> ." +

            "ex:anno2 a oa:Annotation ;" +
            "   oa:hasBody ex:body2 ;" +
            "   oa:hasTarget ex:target2 ." +

            "ex:body2 a dctypes:Sound ." +
            "ex:target2 a dctypes:Image .";

    private final static String TURTLE3 = "@prefix oa: <http://www.w3.org/ns/oa#> ." +
            "@prefix ex: <http://www.example.com/ns#> ." +
            "@prefix dctypes: <http://purl.org/dc/dcmitype/> ." +
<commit_msg>Changed inner classes to interfaces<commit_after>package com.github.anno4j.persistence;

import com.github.anno4j.model.Annotation;
import com.github.anno4j.model.Body;
import com.github.anno4j.model.Target;
import com.github.anno4j.model.namespaces.DCTYPES;
import com.github.anno4j.model.namespaces.RDF;
import com.github.anno4j.persistence.impl.ObjectParser;
import org.junit.Test;
import org.openrdf.annotations.Iri;
import org.openrdf.repository.RepositoryException;
import org.openrdf.repository.config.RepositoryConfigException;
import org.openrdf.rio.RDFFormat;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

import static org.junit.Assert.assertEquals;

/**
 * Testsuite testing the {@link ObjectParser} class.
 */
public class ObjectParserTest {

    @Test
    public void testJSONLD() {

        try {
            URL url = new URL("http://example.com/");

            ObjectParser objectParser = new ObjectParser();
            List<Annotation> annotations = objectParser.parse(JSONLD, url, RDFFormat.JSONLD);

            for(Annotation anno : annotations) {
                System.out.println(anno.toString());
            }

            assertEquals(1, annotations.size());

            objectParser.shutdown();
        } catch (RepositoryException | MalformedURLException | RepositoryConfigException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void testTurtle() {
        try {
            URL url = new URL("http://example.com/");

            ObjectParser objectParser = new ObjectParser();
            List<Annotation> annotations = objectParser.parse(TURTLE, url, RDFFormat.TURTLE);

            for(Annotation anno : annotations) {
                System.out.println(anno.toString());
            }

            assertEquals(1, annotations.size());

            objectParser.shutdown();
        } catch (IOException | RepositoryException | RepositoryConfigException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void testMultipleTurtle() {
        try {
            URL url = new URL("http://example.com/");

            ObjectParser objectParser = new ObjectParser();

            objectParser.parse(TURTLE, url, RDFFormat.TURTLE);
            objectParser.parse(TURTLE2, url, RDFFormat.TURTLE);
            List<Annotation> annotations = objectParser.parse(TURTLE3, url, RDFFormat.TURTLE);

            assertEquals(3, annotations.size());

            for(Annotation anno : annotations) {
                System.out.println(anno.toString());
            }

            objectParser.shutdown();
        } catch (IOException | RepositoryException | RepositoryConfigException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void testMultipleInOneTurtle() {
        try {
            URL url = new URL("http://example.com/");

            ObjectParser objectParser = new ObjectParser();
            List<Annotation> annotations = objectParser.parse(TURTLE_MULTIPLE, url, RDFFormat.TURTLE);

            assertEquals(3, annotations.size());

            for(Annotation anno : annotations) {
                System.out.println(anno.toString());
            }

            objectParser.shutdown();
        } catch (IOException | RepositoryException | RepositoryConfigException e) {
            e.printStackTrace();
        }
    }

    /**
     * Inner class to represent a sound media item.
     */
    @Iri(DCTYPES.SOUND)
    public static interface Sound extends Body {

        @Iri(RDF.VALUE)
        String getValue();

        @Iri(RDF.VALUE)
        void setValue(String value);
    }

    /**
     * Inner class to represent an image media file as body.
     */
    @Iri(DCTYPES.IMAGE)
    public static interface Image extends Target {}

    private final static String TURTLE = "@prefix oa: <http://www.w3.org/ns/oa#> ." +
            "@prefix ex: <http://www.example.com/ns#> ." +
            "@prefix dctypes: <http://purl.org/dc/dcmitype/> ." +
            "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> ." +

            "ex:anno1 a oa:Annotation ;" +
            "   oa:hasBody ex:body1 ;" +
            "   oa:hasTarget ex:target1 ." +

            "ex:body1 a dctypes:Sound ;" +
            "   rdf:value \"somevalue\" ." +
            "ex:target1 a dctypes:Image .";

    private final static String TURTLE2 = "@prefix oa: <http://www.w3.org/ns/oa#> ." +
            "@prefix ex: <http://www.example.com/ns#> ." +
            "@prefix dctypes: <http://purl.org/dc/dcmitype/> ." +

            "ex:anno2 a oa:Annotation ;" +
            "   oa:hasBody ex:body2 ;" +
            "   oa:hasTarget ex:target2 ." +

            "ex:body2 a dctypes:Sound ." +
            "ex:target2 a dctypes:Image .";

    private final static String TURTLE3 = "@prefix oa: <http://www.w3.org/ns/oa#> ." +
            "@prefix ex: <http://www.example.com/ns#> ." +
            "@prefix dctypes: <http://purl.org/dc/dcmitype/> ." +

{'fraction_non_alphanumeric': 0.12605680630759, 'fraction_numerical': 0.00702954307969982, 'mean_word_length': 2.047178002894356, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 14, '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': '1221959', 'n_tokens_mistral': 3186, 'n_tokens_neox': 3069, 'n_words': 611}