DataRepositorySpec.scala 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (C) 2020 Prasoon Joshi
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. package persistence
  18. import org.scalatest._
  19. import utils.FileUtils
  20. import com.lucidchart.open.xtract.XmlReader
  21. import models._
  22. import repository.{DataRepository,MockDataRepository}
  23. import scala.xml.NodeSeq
  24. import scala.xml.Node
  25. class DataRepositorySpec
  26. extends FlatSpec
  27. with Matchers {
  28. "RDF xml document" should "convert to a Subject type" in {
  29. import com.lucidchart.open.xtract.ParseError
  30. val line1 =
  31. <rdf:RDF xmlns:cs="http://purl.org/vocab/changeset/schema#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:skos="http://www.w3.org/2004/02/skos/core#">
  32. <rdf:Description rdf:about="http://id.loc.gov/authorities/subjects/sh2009114899">
  33. <skos:inScheme rdf:resource="http://id.loc.gov/authorities/subjects"/>
  34. <skos:editorial>[Record generated for validation purposes.]</skos:editorial>
  35. <rdf:type rdf:resource="http://www.w3.org/2004/02/skos/core#Concept"/>
  36. <skos:changeNote rdf:nodeID="N6748fa73aad147d19262a7904059d410"/>
  37. <skos:prefLabel xml:lang="en">Anarchism--Italy--History--20th century</skos:prefLabel>
  38. </rdf:Description>
  39. <rdf:Description rdf:nodeID="N6748fa73aad147d19262a7904059d410">
  40. <cs:creatorName rdf:resource="http://id.loc.gov/vocabulary/organizations/dlc"/>
  41. <cs:createdDate rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2009-05-05T00:00:00</cs:createdDate>
  42. <rdf:type rdf:resource="http://purl.org/vocab/changeset/schema#ChangeSet"/>
  43. <cs:subjectOfChange rdf:resource="http://id.loc.gov/authorities/subjects/sh2009114899"/>
  44. <cs:changeReason rdf:datatype="http://www.w3.org/2001/XMLSchema#string">new</cs:changeReason>
  45. </rdf:Description>
  46. </rdf:RDF>
  47. val line2 =
  48. <rdf:RDF xmlns:cs="http://purl.org/vocab/changeset/schema#" xmlns:ns1="http://www.loc.gov/mads/rdf/v1#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:skos="http://www.w3.org/2004/02/skos/core#" xmlns:skosxl="http://www.w3.org/2008/05/skos-xl#">
  49. <rdf:Description rdf:about="http://id.worldcat.org/fast/1165538">
  50. <ns1:authoritativeLabel>"Vertebral vein" </ns1:authoritativeLabel>
  51. </rdf:Description>
  52. <rdf:Description rdf:nodeID="Ne49c15dc2756477d8e0f0f64673e2f7f">
  53. <cs:subjectOfChange rdf:resource="http://id.loc.gov/authorities/subjects/sh85142899"/>
  54. <cs:changeReason rdf:datatype="http://www.w3.org/2001/XMLSchema#string">new</cs:changeReason>
  55. <rdf:type rdf:resource="http://purl.org/vocab/changeset/schema#ChangeSet"/>
  56. <cs:creatorName rdf:resource="http://id.loc.gov/vocabulary/organizations/dlc"/>
  57. <cs:createdDate rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">1986-02-11T00:00:00</cs:createdDate>
  58. </rdf:Description>
  59. <rdf:Description rdf:nodeID="N1aeb44f8edcd42498dcbce59cd5f1741">
  60. <cs:subjectOfChange rdf:resource="http://id.loc.gov/authorities/subjects/sh85142899"/>
  61. <cs:changeReason rdf:datatype="http://www.w3.org/2001/XMLSchema#string">revised</cs:changeReason>
  62. <rdf:type rdf:resource="http://purl.org/vocab/changeset/schema#ChangeSet"/>
  63. <cs:createdDate rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">1991-07-26T15:44:11</cs:createdDate>
  64. <cs:creatorName rdf:resource="http://id.loc.gov/vocabulary/organizations/dlc"/>
  65. </rdf:Description>
  66. <rdf:Description rdf:about="http://id.loc.gov/authorities/subjects/sh85142899">
  67. <ns1:hasCloseExternalAuthority rdf:resource="http://id.worldcat.org/fast/1165538"/>
  68. <skosxl:altLabel rdf:nodeID="N7691dbd120584f2fb065812d6f335f51"/>
  69. <rdf:type rdf:resource="http://www.w3.org/2004/02/skos/core#Concept"/>
  70. <skos:broader rdf:resource="http://id.loc.gov/authorities/subjects/sh85142544"/>
  71. <skos:prefLabel xml:lang="en">Vertebral vein</skos:prefLabel>
  72. <skos:changeNote rdf:nodeID="N1aeb44f8edcd42498dcbce59cd5f1741"/>
  73. <skos:altLabel xml:lang="en">Vena vertebralis</skos:altLabel>
  74. <skos:changeNote rdf:nodeID="Ne49c15dc2756477d8e0f0f64673e2f7f"/>
  75. <skos:inScheme rdf:resource="http://id.loc.gov/authorities/subjects"/>
  76. </rdf:Description>
  77. <rdf:Description rdf:nodeID="N7691dbd120584f2fb065812d6f335f51">
  78. <skosxl:literalForm xml:lang="en">Vena vertebralis</skosxl:literalForm>
  79. <rdf:type rdf:resource="http://www.w3.org/2008/05/skos-xl#Label"/>
  80. </rdf:Description>
  81. <rdf:Description rdf:about="http://id.loc.gov/authorities/subjects/sh85142544">
  82. <rdf:type rdf:resource="http://www.w3.org/2004/02/skos/core#Concept"/>
  83. <skos:prefLabel xml:lang="en">Veins</skos:prefLabel>
  84. </rdf:Description>
  85. </rdf:RDF>
  86. val rdf: String = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  87. val descriptions =
  88. (line2 \ "Description")
  89. .filterNot(n => (n \ "inScheme" \@ raw"{$rdf}resource").isEmpty )
  90. val subject: Seq[Subject] = (for {
  91. d <- descriptions
  92. prefLabel <- (d \ "prefLabel").map(_.text)
  93. inScheme <- (d \ "inScheme").map(l => l \@ raw"{$rdf}resource")
  94. id <- d.map(i => i \@ raw"{$rdf}about")
  95. } yield Subject("graphId", EntityType.Subject, prefLabel, inScheme, id, true))
  96. println(subject.head)
  97. val id = (line2 \ "Description").map(d => d \@ raw"{$rdf}about")
  98. println(id)
  99. }
  100. }