<commit_before>package es.weso.shacl.converter


import org.scalatest._
import org.scalatest.prop._
import com.hp.hpl.jena.rdf.model._
import org.apache.jena.riot.RDFDataMgr
import java.io.StringReader
import org.apache.jena.riot.RDFLanguages
import es.weso.shacl.Schema
import es.weso.rdf.jena.RDFAsJenaModel

class Schema2RDFTest extends FunSpecLike
    with Matchers
    with Checkers {

  describe("Schema2RDF") {

      it("Should convert a simple definition") {
        val schemaStr = """|prefix : <http://example.org/>
                     |:a { :b IRI }
                     |""".stripMargin
                     
        val expectedStr = """|@prefix :      <http://example.org/> .
                          |@prefix sh:    <http://www.w3.org/ns/shacl#> .
                          |@prefix xsd:   <http://www.w3.org/2001/XMLSchema#> .
                          |
                          |:a      a sh:Shape ;
                          |  sh:property  [ a             sh:PropertyConstraint ;
                          |  sh:maxCount   1 ;
                          |  sh:minCount   1 ;
                          |  sh:nodeKind   sh:IRI ;
                          |  sh:predicate  :b ] .""".stripMargin
                          
        val expectedModel = ModelFactory.createDefaultModel;
        val reader = new StringReader(expectedStr) ;
        RDFDataMgr.read(expectedModel, reader, null, RDFLanguages.TURTLE) ;
        
        val (schema,pm) = Schema.fromString(schemaStr).get
        val rdf = RDFAsJenaModel.empty
        Schema2RDF.schema2RDF(schema,rdf)
        val convertedModel = rdf.model
        if (convertedModel.isIsomorphicWith(expectedModel)) {
          println("Are isomorphic")
        } else {
          println("Models are not equivalent")
          println("Converted model")
          convertedModel.write(System.out, "TURTLE")
          println("Expected model")
          expectedModel.write(System.out, "TURTLE")
        }
      }

    }
}<commit_msg>Refactor RDF2SchemaTest<commit_after>package es.weso.shacl.converter

import org.scalatest._
import org.scalatest.prop._
import com.hp.hpl.jena.rdf.model._
import org.apache.jena.riot.RDFDataMgr
import java.io.StringReader
import org.apache.jena.riot.RDFLanguages
import es.weso.shacl.Schema
import es.weso.rdf.jena.RDFAsJenaModel
import es.weso.utils.JenaUtils
import util._

class Schema2RDFTest extends FunSpecLike
    with Matchers
    with Checkers {

  describe("Schema2RDF") {

    it("Should convert a simple definition") {
      val schemaStr = """|prefix : <http://example.org/>
                     |:a { :b IRI }
                     |""".stripMargin

      val expectedStr = """|@prefix :      <http://example.org/> .
                          |@prefix sh:    <http://www.w3.org/ns/shacl#> .
                          |@prefix xsd:   <http://www.w3.org/2001/XMLSchema#> .
                          |
                          |:a      a sh:Shape ;
                          |  sh:property  [ a             sh:PropertyConstraint ;
                          |  sh:maxCount   1 ;
                          |  sh:minCount   1 ;
                          |  sh:nodeKind   sh:IRI ;
                          |  sh:predicate  :b ] .""".stripMargin

      val rdf = RDFAsJenaModel(ModelFactory.createDefaultModel())
      val tryConvert = for {
        expectedModel <- JenaUtils.parseFromString(expectedStr)
        (schema, pm) <- Schema.fromString(schemaStr)
      } yield (expectedModel, schema)

      tryConvert match {
        case Success((expectedModel, schema)) => {
          val convertedModel = rdf.model
          if (convertedModel.isIsomorphicWith(expectedModel)) {
            println("Are isomorphic")
          } else {
            println("Models are not equivalent")
            println("Converted model")
            convertedModel.write(System.out, "TURTLE")
            println("Expected model")
            expectedModel.write(System.out, "TURTLE")
          }

        }
        case Failure(e) => fail(s"Error converting $e")
      }

    }

  }
}
{'fraction_non_alphanumeric': 0.10939416237429482, 'fraction_numerical': 0.00564140299239637, 'mean_word_length': 1.6411917098445596, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1085677', 'n_tokens_mistral': 1228, 'n_tokens_neox': 1199, 'n_words': 217}