123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- /*
- * Copyright (C) 2020 Prasoon Joshi
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
- package persistence
- import org.scalatest._
- import utils.FileUtils
- import com.lucidchart.open.xtract.XmlReader
- import models._
- import repository.{DataRepository,MockDataRepository}
- import scala.xml.NodeSeq
- import scala.xml.Node
- class DataRepositorySpec
- extends FlatSpec
- with Matchers {
- "RDF xml document" should "convert to a Subject type" in {
- import com.lucidchart.open.xtract.ParseError
- val line1 =
- <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#">
- <rdf:Description rdf:about="http://id.loc.gov/authorities/subjects/sh2009114899">
- <skos:inScheme rdf:resource="http://id.loc.gov/authorities/subjects"/>
- <skos:editorial>[Record generated for validation purposes.]</skos:editorial>
- <rdf:type rdf:resource="http://www.w3.org/2004/02/skos/core#Concept"/>
- <skos:changeNote rdf:nodeID="N6748fa73aad147d19262a7904059d410"/>
- <skos:prefLabel xml:lang="en">Anarchism--Italy--History--20th century</skos:prefLabel>
- </rdf:Description>
- <rdf:Description rdf:nodeID="N6748fa73aad147d19262a7904059d410">
- <cs:creatorName rdf:resource="http://id.loc.gov/vocabulary/organizations/dlc"/>
- <cs:createdDate rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2009-05-05T00:00:00</cs:createdDate>
- <rdf:type rdf:resource="http://purl.org/vocab/changeset/schema#ChangeSet"/>
- <cs:subjectOfChange rdf:resource="http://id.loc.gov/authorities/subjects/sh2009114899"/>
- <cs:changeReason rdf:datatype="http://www.w3.org/2001/XMLSchema#string">new</cs:changeReason>
- </rdf:Description>
- </rdf:RDF>
- val line2 =
- <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#">
- <rdf:Description rdf:about="http://id.worldcat.org/fast/1165538">
- <ns1:authoritativeLabel>"Vertebral vein" </ns1:authoritativeLabel>
- </rdf:Description>
- <rdf:Description rdf:nodeID="Ne49c15dc2756477d8e0f0f64673e2f7f">
- <cs:subjectOfChange rdf:resource="http://id.loc.gov/authorities/subjects/sh85142899"/>
- <cs:changeReason rdf:datatype="http://www.w3.org/2001/XMLSchema#string">new</cs:changeReason>
- <rdf:type rdf:resource="http://purl.org/vocab/changeset/schema#ChangeSet"/>
- <cs:creatorName rdf:resource="http://id.loc.gov/vocabulary/organizations/dlc"/>
- <cs:createdDate rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">1986-02-11T00:00:00</cs:createdDate>
- </rdf:Description>
- <rdf:Description rdf:nodeID="N1aeb44f8edcd42498dcbce59cd5f1741">
- <cs:subjectOfChange rdf:resource="http://id.loc.gov/authorities/subjects/sh85142899"/>
- <cs:changeReason rdf:datatype="http://www.w3.org/2001/XMLSchema#string">revised</cs:changeReason>
- <rdf:type rdf:resource="http://purl.org/vocab/changeset/schema#ChangeSet"/>
- <cs:createdDate rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">1991-07-26T15:44:11</cs:createdDate>
- <cs:creatorName rdf:resource="http://id.loc.gov/vocabulary/organizations/dlc"/>
- </rdf:Description>
- <rdf:Description rdf:about="http://id.loc.gov/authorities/subjects/sh85142899">
- <ns1:hasCloseExternalAuthority rdf:resource="http://id.worldcat.org/fast/1165538"/>
- <skosxl:altLabel rdf:nodeID="N7691dbd120584f2fb065812d6f335f51"/>
- <rdf:type rdf:resource="http://www.w3.org/2004/02/skos/core#Concept"/>
- <skos:broader rdf:resource="http://id.loc.gov/authorities/subjects/sh85142544"/>
- <skos:prefLabel xml:lang="en">Vertebral vein</skos:prefLabel>
- <skos:changeNote rdf:nodeID="N1aeb44f8edcd42498dcbce59cd5f1741"/>
- <skos:altLabel xml:lang="en">Vena vertebralis</skos:altLabel>
- <skos:changeNote rdf:nodeID="Ne49c15dc2756477d8e0f0f64673e2f7f"/>
- <skos:inScheme rdf:resource="http://id.loc.gov/authorities/subjects"/>
- </rdf:Description>
- <rdf:Description rdf:nodeID="N7691dbd120584f2fb065812d6f335f51">
- <skosxl:literalForm xml:lang="en">Vena vertebralis</skosxl:literalForm>
- <rdf:type rdf:resource="http://www.w3.org/2008/05/skos-xl#Label"/>
- </rdf:Description>
- <rdf:Description rdf:about="http://id.loc.gov/authorities/subjects/sh85142544">
- <rdf:type rdf:resource="http://www.w3.org/2004/02/skos/core#Concept"/>
- <skos:prefLabel xml:lang="en">Veins</skos:prefLabel>
- </rdf:Description>
- </rdf:RDF>
- val rdf: String = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
-
- val descriptions =
- (line2 \ "Description")
- .filterNot(n => (n \ "inScheme" \@ raw"{$rdf}resource").isEmpty )
- val subject: Seq[Subject] = (for {
- d <- descriptions
- prefLabel <- (d \ "prefLabel").map(_.text)
- inScheme <- (d \ "inScheme").map(l => l \@ raw"{$rdf}resource")
- id <- d.map(i => i \@ raw"{$rdf}about")
- } yield Subject("graphId", EntityType.Subject, prefLabel, inScheme, id, true))
- println(subject.head)
- val id = (line2 \ "Description").map(d => d \@ raw"{$rdf}about")
- println(id)
- }
- }
|