<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.almibe.ligature.parsers

import org.almibe.ligature.IRI
import org.almibe.ligature.LangLiteral
import org.almibe.ligature.Triple
import org.almibe.ligature.TypedLiteral
import spock.lang.Specification

class TurtleSpec extends Specification {
    final def turtle = new Turtle()
    final def xsd = "http://www.w3.org/2001/XMLSchema#"
    final def foafKnows = new IRI("http://xmlns.com/foaf/0.1/knows")
    final def rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"

    final def spidermanEnemy = new Triple(new IRI("http://example.org/#spiderman"),
        new IRI("http://www.perceive.net/schemas/relationship/enemyOf"), new IRI("http://example.org/#green-goblin"))

    final def spidermanName = new Triple(new IRI("http://example.org/#spiderman"),
        new IRI("http://xmlns.com/foaf/0.1/name"), new TypedLiteral("Spiderman", new IRI("http://www.w3.org/2001/XMLSchema#string")))

    final def spidermanNameRu = new Triple(new IRI("http://example.org/#spiderman"),
        new IRI("http://xmlns.com/foaf/0.1/name"), new LangLiteral("Человек-паук", "ru"))
    final def stringIRI = new IRI("http://www.w3.org/2001/XMLSchema#string")

    final def "support basic IRI triple"() {
        given:
        final def expectedResult = spidermanEnemy
        final def results = turtle.parseTurtle(this.class.getResource("/turtle/01-basicTriple.ttl").text)
        expect:
        results.size() == 1
        results.first() == expectedResult
    }

    final def "support predicate lists"() {
        given:
        final def expectedResults = [spidermanEnemy, spidermanName]
        final def results = turtle.parseTurtle(this.class.getResource("/turtle/02-predicateList.ttl").text)
        expect:
        results.size() == 2
        results == expectedResults
    }

    final def "support object lists"() {
        given:
        final def expectedResults = [spidermanName, spidermanNameRu, spidermanName, spidermanNameRu]
        final def results = turtle.parseTurtle(this.class.getResource("/turtle/03-objectList.ttl").text)
        expect:
        results.size() == 4
        results == expectedResults
    }

    final def "support comments"() {
        given:
        final def expectedResults = [spidermanEnemy, spidermanName]
        final def results = turtle.parseTurtle(this.class.getResource("/turtle/04-comments.ttl").text)
        expect:
        results.size() == 2
        results == expectedResults
    }

    final def "support multiline triples"() {
        given:
        final def expectedResults = [spidermanEnemy]
        final def results = turtle.parseTurtle(this.class.getResource("/turtle/05-multilineTriple.ttl").text)
        expect:
        results.size() == 1
        results == expectedResults
    }

    final def base = "http://one.example/"
    final def base2 = "http://one.example2/"
    final def baseTwo = "http://two.example/"
    final def baseTwo2 = "http://two.example2/"
    final def base3 = "http://another.example/"

    final def "turtle IRI parsing with base"() {
        given:
        final def expectedResults = [
            new Triple(new IRI("${base}subject2"), new IRI("${base}predicate2"), new IRI("${base}object2")),
            new Triple(new IRI("${base2}subject2"), new IRI("${base2}predicate2"), new IRI("${base2}object2")),
        ]
        final def results = turtle.parseTurtle(this.class.getResource("/turtle/06-baseTriples.ttl").text)
        expect:
        results[0] == expectedResults[0]
        results[1] == expectedResults[1]
    }

    final def "turtle IRI parsing with prefixes"() {
        given:
        final def expectedResults = [
                new Triple(new IRI("${baseTwo}subject3"), new IRI("${baseTwo}predicate3"), new IRI("${baseTwo}object3")),
                new Triple(new IRI("${baseTwo2}subject3"), new IRI("${baseTwo2}predicate3"), new IRI("${baseTwo2}object3")),
                new Triple(new IRI("${base2}path/subject4"), new IRI("${base2}path/predicate4"), new IRI("${base2}path/object4")),
                new Triple(new IRI("${base3}subject5"), new IRI("${base3}predicate5"), new IRI("${base3}object5")),
                new Triple(new IRI("${base3}subject6"), new IRI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), new IRI("${base3}subject7")),
                new Triple(new IRI("http://伝言.example/?user=أكرم&amp;channel=R%26D"), new IRI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), new IRI("${base3}subject8"))
        ]
        final def results = turtle.parseTurtle(this.class.getResource("/turtle/07-prefixTriples.ttl").text)
        expect:
        results[0] == expectedResults[0]
        results[1] == expectedResults[1]
        results[2] == expectedResults[2]
        results[3] == expectedResults[3]
        results[4] == expectedResults[4]
        results[5] == expectedResults[5]
    }

    final def "support language literals"() {
        given:
        final def expectedResults = [spidermanNameRu]
        final def results = turtle.parseTurtle(this.class.getResource("/turtle/08-literalWithLanguage.ttl").text)
        expect:
        results == expectedResults
    }

    final def "support quoted literals"() {
        given:
        final def base = "http://www.libraryweasel.org/fake/madeup#"
        final def show = new IRI("http://example.org/vocab/show/218")
        final def show219 = new IRI("http://example.org/vocab/show/219")
        final def label = new IRI("http://www.w3.org/2000/01/rdf-schema#label")
        final def localName = new IRI("http://example.org/vocab/show/localName")
        final def blurb = new IRI("http://example.org/vocab/show/blurb")
        final def multilineText = "This is a multi-line\n" +
            "literal with many quotes (\"\"\"\"\")\n" +
            "and up to two sequential apostrophes ('')."
        final def multilineText2 = "Another\n" +
            "multiline string with' 'a' \"custom datatype\"\\\"."
        final def expectedResults = [
            new Triple(show, label, new TypedLiteral("That Seventies Show", stringIRI)),
            new Triple(show, label, new TypedLiteral("That Seventies Show", stringIRI)),
            new Triple(show, label, new TypedLiteral("That Seventies Show", stringIRI)),
            new Triple(show, new IRI("${base}pred"), new TypedLiteral("That Seventies Show", new IRI("${base}string"))),
            new Triple(show, localName, new LangLiteral("That Seventies Show", "en")),
            new Triple(show, localName, new LangLiteral("Cette Série des Années Soixante-dix", "fr")),
            new Triple(show, localName, new LangLiteral("Cette Série des Années Septante", "fr-be")),
            new Triple(show, blurb, new TypedLiteral(multilineText, stringIRI)),
            new Triple(show219, blurb, new TypedLiteral(multilineText2, new IRI("${base}long-string"))),
            new Triple(show219, blurb, new TypedLiteral("", stringIRI)),
            new Triple(show219, blurb, new TypedLiteral("", stringIRI)),
            new Triple(show219, blurb, new TypedLiteral("", stringIRI))
        ]
        final def results = turtle.parseTurtle(this.class.getResource("/turtle/09-quotedLiterals.ttl").text)
        expect:
        results == expectedResults
    }
////
////    final def supportNumbers() {
////        final def helium = "http://en.wikipedia.org/wiki/Helium"
////        final def prefix = "http://example.org/elements"
////        final def expectedResults = [
////            new Triple(new IRI(helium), new IRI("${prefix}atomicNumber"), new TypedLiteral("2", new IRI("${xsd}integer"))),
////            new Triple(new IRI(helium), new IRI("${prefix}atomicMass"), new TypedLiteral("4.002602", new IRI("${xsd}float"))),
////            new Triple(new IRI(helium), new IRI("${prefix}specificGravity"), new TypedLiteral("1.663E-4", new IRI("${xsd}double")))
////        )
////        final def results = turtle.parseTurtle(this.class.getResource("/turtle/numbers.ttl").text)
////        results == expectedResults
////    }
////
////    final def supportBooleans() {
////        final def expectedResults = [
////            new Triple(new IRI("http://somecountry.example/census2007"), new IRI("http://example.org/stats/isLandlocked"),
////                    new TypedLiteral("false", new IRI("${xsd}boolean")))
////        )
////        final def results = turtle.parseTurtle(this.class.getResource("/turtle/booleans.ttl").text)
////        results == expectedResults
////    }
////
////    final def supportBlankNodes() {
////        final def expectedResults = [
////            new Triple(BlankNode("alice"), new IRI("http://xmlns.com/foaf/0.1/knows"), BlankNode("bob")),
////            new Triple(BlankNode("bob"), new IRI("http://xmlns.com/foaf/0.1/knows"), BlankNode("alice"))
////        )
////        final def results = turtle.parseTurtle(this.class.getResource("/turtle/blankNodes.ttl").text)
////        results == expectedResults
////    }<commit_msg>commenting out tests before doing lexer rewrite<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.almibe.ligature.parsers

import org.almibe.ligature.IRI
import org.almibe.ligature.LangLiteral
import org.almibe.ligature.Triple
import org.almibe.ligature.TypedLiteral
import spock.lang.Specification

class TurtleSpec extends Specification {
    final def turtle = new Turtle()
    final def xsd = "http://www.w3.org/2001/XMLSchema#"
    final def foafKnows = new IRI("http://xmlns.com/foaf/0.1/knows")
    final def rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"

    final def spidermanEnemy = new Triple(new IRI("http://example.org/#spiderman"),
        new IRI("http://www.perceive.net/schemas/relationship/enemyOf"), new IRI("http://example.org/#green-goblin"))

    final def spidermanName = new Triple(new IRI("http://example.org/#spiderman"),
        new IRI("http://xmlns.com/foaf/0.1/name"), new TypedLiteral("Spiderman", new IRI("http://www.w3.org/2001/XMLSchema#string")))

    final def spidermanNameRu = new Triple(new IRI("http://example.org/#spiderman"),
        new IRI("http://xmlns.com/foaf/0.1/name"), new LangLiteral("Человек-паук", "ru"))
    final def stringIRI = new IRI("http://www.w3.org/2001/XMLSchema#string")

    final def "support basic IRI triple"() {
        given:
        final def expectedResult = spidermanEnemy
        final def results = turtle.parseTurtle(this.class.getResource("/turtle/01-basicTriple.ttl").text)
        expect:
        results.size() == 1
        results.first() == expectedResult
    }

//    final def "support predicate lists"() {
//        given:
//        final def expectedResults = [spidermanEnemy, spidermanName]
//        final def results = turtle.parseTurtle(this.class.getResource("/turtle/02-predicateList.ttl").text)
//        expect:
//        results.size() == 2
//        results == expectedResults
//    }
//
//    final def "support object lists"() {
//        given:
//        final def expectedResults = [spidermanName, spidermanNameRu, spidermanName, spidermanNameRu]
//        final def results = turtle.parseTurtle(this.class.getResource("/turtle/03-objectList.ttl").text)
//        expect:
//        results.size() == 4
//        results == expectedResults
//    }
//
//    final def "support comments"() {
//        given:
//        final def expectedResults = [spidermanEnemy, spidermanName]
//        final def results = turtle.parseTurtle(this.class.getResource("/turtle/04-comments.ttl").text)
//        expect:
//        results.size() == 2
//        results == expectedResults
//    }
//
//    final def "support multiline triples"() {
//        given:
//        final def expectedResults = [spidermanEnemy]
//        final def results = turtle.parseTurtle(this.class.getResource("/turtle/05-multilineTriple.ttl").text)
//        expect:
//        results.size() == 1
//        results == expectedResults
//    }
//
//    final def base = "http://one.example/"
//    final def base2 = "http://one.example2/"
//    final def baseTwo = "http://two.example/"
//    final def baseTwo2 = "http://two.example2/"
//    final def base3 = "http://another.example/"
//
//    final def "turtle IRI parsing with base"() {
//        given:
//        final def expectedResults = [
//            new Triple(new IRI("${base}subject2"), new IRI("${base}predicate2"), new IRI("${base}object2")),
//            new Triple(new IRI("${base2}subject2"), new IRI("${base2}predicate2"), new IRI("${base2}object2")),
//        ]
//        final def results = turtle.parseTurtle(this.class.getResource("/turtle/06-baseTriples.ttl").text)
//        expect:
//        results[0] == expectedResults[0]
//        results[1] == expectedResults[1]
//    }
//
//    final def "turtle IRI parsing with prefixes"() {
//        given:
//        final def expectedResults = [
//                new Triple(new IRI("${baseTwo}subject3"), new IRI("${baseTwo}predicate3"), new IRI("${baseTwo}object3")),
//                new Triple(new IRI("${baseTwo2}subject3"), new IRI("${baseTwo2}predicate3"), new IRI("${baseTwo2}object3")),
//                new Triple(new IRI("${base2}path/subject4"), new IRI("${base2}path/predicate4"), new IRI("${base2}path/object4")),
//                new Triple(new IRI("${base3}subject5"), new IRI("${base3}predicate5"), new IRI("${base3}object5")),
//                new Triple(new IRI("${base3}subject6"), new IRI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), new IRI("${base3}subject7")),
//                new Triple(new IRI("http://伝言.example/?user=أكرم&amp;channel=R%26D"), new IRI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), new IRI("${base3}subject8"))
//        ]
//        final def results = turtle.parseTurtle(this.class.getResource("/turtle/07-prefixTriples.ttl").text)
//        expect:
//        results[0] == expectedResults[0]
//        results[1] == expectedResults[1]
//        results[2] == expectedResults[2]
//        results[3] == expectedResults[3]
//        results[4] == expectedResults[4]
//        results[5] == expectedResults[5]
//    }
//
//    final def "support language literals"() {
//        given:
//        final def expectedResults = [spidermanNameRu]
//        final def results = turtle.parseTurtle(this.class.getResource("/turtle/08-literalWithLanguage.ttl").text)
//        expect:
//        results == expectedResults
//    }
//
//    final def "support quoted literals"() {
//        given:
//        final def base = "http://www.libraryweasel.org/fake/madeup#"
//        final def show = new IRI("http://example.org/vocab/show/218")
//        final def show219 = new IRI("http://example.org/vocab/show/219")
//        final def label = new IRI("http://www.w3.org/2000/01/rdf-schema#label")
//        final def localName = new IRI("http://example.org/vocab/show/localName")
//        final def blurb = new IRI("http://example.org/vocab/show/blurb")
//        final def multilineText = "This is a multi-line\n" +
//            "literal with many quotes (\"\"\"\"\")\n" +
//            "and up to two sequential apostrophes ('')."
//        final def multilineText2 = "Another\n" +
//            "multiline string with' 'a' \"custom datatype\"\\\"."
//        final def expectedResults = [
//            new Triple(show, label, new TypedLiteral("That Seventies Show", stringIRI)),
//            new Triple(show, label, new TypedLiteral("That Seventies Show", stringIRI)),
//            new Triple(show, label, new TypedLiteral("That Seventies Show", stringIRI)),
//            new Triple(show, new IRI("${base}pred"), new TypedLiteral("That Seventies Show", new IRI("${base}string"))),
//            new Triple(show, localName, new LangLiteral("That Seventies Show", "en")),
//            new Triple(show, localName, new LangLiteral("Cette Série des Années Soixante-dix", "fr")),
//            new Triple(show, localName, new LangLiteral("Cette Série des Années Septante", "fr-be")),
//            new Triple(show, blurb, new TypedLiteral(multilineText, stringIRI)),
//            new Triple(show219, blurb, new TypedLiteral(multilineText2, new IRI("${base}long-string"))),
//            new Triple(show219, blurb, new TypedLiteral("", stringIRI)),
//            new Triple(show219, blurb, new TypedLiteral("", stringIRI)),
//            new Triple(show219, blurb, new TypedLiteral("", stringIRI))
//        ]
//        final def results = turtle.parseTurtle(this.class.getResource("/turtle/09-quotedLiterals.ttl").text)
//        expect:
//        results == expectedResults
//    }
////
////    final def supportNumbers() {
////        final def helium = "http://en.wikipedia.org/wiki/Helium"
////        final def prefix = "http://example.org/elements"
////        final def expectedResults = [
////            new Triple(new IRI(helium), new IRI("${prefix}atomicNumber"), new TypedLiteral("2", new IRI("${xsd}integer"))),
////            new Triple(new IRI(helium), new IRI("${prefix}atomicMass"), new TypedLiteral("4.002602", new IRI("${xsd}float"))),
////            new Triple(new IRI(helium), new IRI("${prefix}specificGravity"), new TypedLiteral("1.663E-4", new IRI("${xsd}double")))
////        )
////        final def results = turtle.parseTurtle(this.class.getResource("/turtle/numbers.ttl").text)
////        results == expectedResults
////    }
////
////    final def supportBooleans() {
////        final def expectedResults = [
////            new Triple(new IRI("http://somecountry.example/census2007"), new IRI("http://example.org/stats/isLandlocked"),
////                    new TypedLiteral("false", new IRI("${xsd}boolean")))
////        )
////        final def results = turtle.parseTurtle(this.class.getResource("/turtle/booleans.ttl").text)
////        results == expectedResults
////    }
////
////    final def supportBlankNodes() {
////        final def expectedResults = [
////            new Triple(BlankNode("alice"), new IRI("http://xmlns.com/foaf/0.1/knows"), BlankNode("bob")),
////            new Triple(BlankNode("bob"), new IRI("http://xmlns.com/foaf/0.1/knows"), BlankNode("alice"))
////        )
////        final def results = turtle.parseTurtle(this.class.getResource("/turtle/blankNodes.ttl").text)
////        results == expectedResults
////    }
{'fraction_non_alphanumeric': 0.1687850064627316, 'fraction_numerical': 0.01992675570874623, 'mean_word_length': 2.670488238782368, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 18, 'xml': 10}, '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': '3138543', 'n_tokens_mistral': 6182, 'n_tokens_neox': 5745, 'n_words': 1214}