File: rdf_add.Rd

package info (click to toggle)
r-cran-rdflib 0.2.9%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 596 kB
  • sloc: xml: 66; sh: 13; makefile: 2
file content (93 lines) | stat: -rw-r--r-- 3,167 bytes parent folder | download | duplicates (3)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/rdf_add.R
\name{rdf_add}
\alias{rdf_add}
\title{Add RDF Triples}
\usage{
rdf_add(
  rdf,
  subject,
  predicate,
  object,
  subjectType = as.character(NA),
  objectType = as.character(NA),
  datatype_uri = as.character(NA)
)
}
\arguments{
\item{rdf}{an rdf object}

\item{subject}{character string containing the subject}

\item{predicate}{character string containing the predicate}

\item{object}{character string containing the object}

\item{subjectType}{the Node type of the subject, i.e. "uri", "blank"}

\item{objectType}{the Node type of the object, i.e. "literal", "uri", "blank"}

\item{datatype_uri}{the datatype URI to associate with a object literal value}
}
\value{
Silently returns the updated RDF graph (rdf object).
Since the rdf object simply contains external pointers
to the model object in C code, note that the input object is modified
directly, so you need not assign the output of rdf_add() to anything.
}
\description{
add a triple (subject, predicate, object) to the RDF graph
}
\details{
\code{rdf_add()} will automatically 'duck type' nodes (if looks like a duck...).
That is, strings that look like URIs will be declared as URIs. (See
\href{https://en.wikipedia.org/wiki/Uniform_Resource_Identifier}{URI}).
Predicate should always be a URI (e.g. URL or  a \code{prefix:string}),
cannot be blank or literal.  Subjects that look like strings will be
treated as \href{https://en.wikipedia.org/wiki/Blank_node}{Blank Nodes} (i.e.
will be prefixed with \verb{_:}).  An empty subject, \code{""}, will create a
blank node with random name.  Objects that look like URIs will be
typed as resource nodes, otherwise as literals.  An empty object \code{""}
will be treated as blank node.  Set \code{subjectType} or \code{objectType}
explicitly to override this behavior, e.g. to treat an object URI
as a literal string.  NAs are also treated as blank nodes in subject
or object  See examples for details.
}
\examples{
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")  
        

}
\references{
\url{https://en.wikipedia.org/wiki/Uniform_Resource_Identifier}
}