File: test-rdf_add.R

package info (click to toggle)
r-cran-rdflib 0.2.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 572 kB
  • sloc: xml: 66; sh: 13; makefile: 2
file content (76 lines) | stat: -rw-r--r-- 2,161 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
testthat::context("RDF Add")

testthat::test_that("we can print.rdf UTF-8", {
  r <- rdf()
  rdf_add(r,
          subject="", 
          predicate="http://schema.org/name", 
          object="Maëlle Salmon")
  
  testthat::expect_output(print(r), "Maëlle")
  rdf_free(r)
})



testthat::test_that("we can initialize add triples to rdf graph", {
  rdf <- rdf()
  rdf <- rdf_add(rdf, 
                 subject="http://www.dajobe.org/",
                 predicate="http://schema.org/dateCreated",
                 object=as.Date("2015-01-01"))
  testthat::expect_is(rdf, "rdf")
  rdf_free(rdf)
  
})


testthat::test_that("we can initialize add triples to rdf graph", {
  rdf <- rdf()
  rdf <- rdf_add(rdf, 
                 subject=NA,
                 predicate="http://schema.org/dateCreated",
                 object=NA)
  testthat::expect_is(rdf, "rdf")
  rdf_free(rdf)
  
})

testthat::test_that("other rdf_add examples work",{
  
   rdf <- rdf()
   rdf_add(rdf, 
       subject="http://www.dajobe.org/",
       predicate="http://purl.org/dc/elements/1.1/language",
       object="en")
       
   ## non-URI string in subject indicates a blank subject
   ## (prefixes to "_:b0")
   rdf_add(rdf, "b0", "http://schema.org/jobTitle", "Professor") 
   
   ## identically a blank subject.  
   ## Note rdf is unchanged when we add the same triple twice.
   rdf_add(rdf, "b0", "http://schema.org/jobTitle", "Professor", 
           subjectType = "blank") 
           
   ## blank node with empty string creates a default blank node id
   rdf_add(rdf, "", "http://schema.org/jobTitle", "Professor")   
                       
   
   ## Subject and Object both recognized as URI resources:
   rdf_add(rdf, 
           "https://orcid.org/0000-0002-1642-628X",
           "http://schema.org/homepage", 
           "http://carlboettiger.info")  
  
    ## Force object to be literal, not URI resource        
   rdf_add(rdf, 
           "https://orcid.org/0000-0002-1642-628X",
           "http://schema.org/homepage", 
           "http://carlboettiger.info",
           objectType = "literal")  
           
  
   testthat::expect_is(rdf, "rdf")
   rdf_free(rdf)
})