<commit_before>package es.weso.shex.shexR

import es.weso.shex._
import org.scalatest._
import es.weso.rdf.jena.RDFAsJenaModel
import es.weso.rdf.nodes._
import es.weso.shex.shexR.PREFIXES._
import es.weso.rdf.PREFIXES._


class RDF2ShExTest extends FunSpec with Matchers with EitherValues with TryValues {
  val rdf2Shex = new RDF2ShEx {}

  describe("Simple schema") {
    it("should parse simple schema") {
      val str =
        """
        |prefix sx: <http://shex.io/ns/shex#>
        |prefix : <http://example.org/>
        |
        |:schema a sx:Schema ;
        |  sx:shapes [ a sx:NodeConstraint ;
        |              sx:nodeKind sx:iri
        |            ] .
      """.
          stripMargin

      val expected = Schema(
        None,
        None,
        None,
        None,
        Some(List(NodeConstraint.nodeKind(IRIKind, List()))),
        None)

      val result = for {
        rdf <- RDFAsJenaModel.fromChars(str, "TURTLE", None)
        schemas <- RDF2ShEx.rdf2Schema(rdf)
      } yield schemas

      result match {
        case Right(schema) => {
          val model1 = ShEx2RDF.shEx2Model(schema, Some(IRI("http://example.org/x")))
          val model2 = ShEx2RDF.shEx2Model(expected, Some(IRI("http://example.org/x")))
          if (model1.isIsomorphicWith(model2)) {
            info(s"Models are isomorphic")
          } else {
            info(s"Schema obtained: ${model1}\nSchema expected: ${model2} are not isomorphic")
            fail("Schemas are not isomorphic")
          }
        }
        case Left(e) => {
          info(s"Failed $e")
          fail(e)
        }
      }
    }

    describe("opt") {

      it("Should pass opt when option exists") {
        val str =
          """|prefix sx: <http://shex.io/ns/shex#>
         |prefix : <http://example.org/>
         |<commit_msg>Repaired one compilation error in shex tests<commit_after>package es.weso.shex.shexR

import es.weso.shex._
import org.scalatest._
import es.weso.rdf.jena.RDFAsJenaModel
import es.weso.rdf.nodes._
import es.weso.shex.shexR.PREFIXES._
import es.weso.rdf.PREFIXES._


class RDF2ShExTest extends FunSpec with Matchers with EitherValues with TryValues {
  val rdf2Shex = new RDF2ShEx {}

  describe("Simple schema") {
    it("should parse simple schema") {
      val str =
        """
        |prefix sx: <http://shex.io/ns/shex#>
        |prefix : <http://example.org/>
        |
        |:schema a sx:Schema ;
        |  sx:shapes [ a sx:NodeConstraint ;
        |              sx:nodeKind sx:iri
        |            ] .
      """.
          stripMargin

      val expected = Schema(
        None,
        None,
        None,
        None,
        Some(List(NodeConstraint.nodeKind(IRIKind, List()))),
        None,
        List())

      val result = for {
        rdf <- RDFAsJenaModel.fromChars(str, "TURTLE", None)
        schemas <- RDF2ShEx.rdf2Schema(rdf)
      } yield schemas

      result match {
        case Right(schema) => {
          val model1 = ShEx2RDF.shEx2Model(schema, Some(IRI("http://example.org/x")))
          val model2 = ShEx2RDF.shEx2Model(expected, Some(IRI("http://example.org/x")))
          if (model1.isIsomorphicWith(model2)) {
            info(s"Models are isomorphic")
          } else {
            info(s"Schema obtained: ${model1}\nSchema expected: ${model2} are not isomorphic")
            fail("Schemas are not isomorphic")
          }
        }
        case Left(e) => {
          info(s"Failed $e")
          fail(e)
        }
      }
    }

    describe("opt") {

      it("Should pass opt when option exists") {
        val str =
          """|prefix sx: <http://shex.io/ns/shex#>
         |prefix : <http://example.org/>
         |
{'fraction_non_alphanumeric': 0.13029403830590774, 'fraction_numerical': 0.008092797410304829, 'mean_word_length': 1.8833592534992223, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7249600', 'n_tokens_mistral': 1249, 'n_tokens_neox': 1229, 'n_words': 247}