/
Prefix.scala
496 lines (485 loc) · 18.3 KB
/
Prefix.scala
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
package org.w3.banana
import scala.util._
trait Prefix[T <: RDFObj](using val rdf: T) {
def prefixName: String
def prefixIri: String
def apply(value: String): rdf.URI
def unapply(iri: rdf.URI): Option[String]
}
object Prefix {
def apply[T <: RDFObj](using rdf: T)(
prefixName: String,
prefixIri: String
)(using ops: RDFOps[rdf.type]): Prefix[rdf.type] =
new PrefixBuilder[T]()(prefixName, prefixIri).asInstanceOf[Prefix[rdf.type]]
}
class PrefixBuilder[T <: RDFObj](using val rdf2: T)(
val prefixName: String,
val prefixIri: String
)(using val ops: RDFOps[rdf2.type]) extends Prefix[rdf2.type](using rdf2) {
import ops._
override def toString: String = "Prefix(" + prefixName + ")"
def apply(value: String): rdf.URI = makeUri(prefixIri + value)
def unapply(iri: rdf.URI): Option[String] = {
val uriString = fromUri(iri)
if (uriString.startsWith(prefixIri))
Some(uriString.substring(prefixIri.length))
else
None
}
def getLocalName(iri: rdf.URI): Try[String] =
unapply(iri) match {
case None => Failure(Exception(this.toString + " couldn't extract localname for " + iri.toString))
case Some(localname) => Success(localname)
}
}
object RDFSPrefix {
def apply[T <: RDFObj](using rdf: T)(using ops: RDFOps[rdf.type]) = new RDFSPrefix()
}
class RDFSPrefix[T <: RDFObj](using val rdf3: T)(using override val ops: RDFOps[rdf3.type])
extends PrefixBuilder[rdf3.type](using rdf3)("rdfs", "http://www.w3.org/2000/01/rdf-schema#") {
val Class = apply("Class")
val Container = apply("Container")
val ContainerMembershipProperty = apply("ContainerMembershipProperty")
val Datatype = apply("Datatype")
val Literal = apply("Literal")
val Resource = apply("Resource")
val comment = apply("comment")
val domain = apply("domain")
val isDefinedBy = apply("isDefinedBy")
val label = apply("label")
val member = apply("member")
val range = apply("range")
val seeAlso = apply("seeAlso")
val subClassOf = apply("subClassOf")
val subPropertyOf = apply("subPropertyOf")
}
//
//object RDFPrefix {
// def apply[T <: RDFObj](using rdf: T)(implicit ops: RDFOps[rdf.type]) = new RDFPrefix()
//}
//
//class RDFPrefix[T <: RDFObj](using val rdf: T)(using val ops: RDFOps[rdf.type])
// extends PrefixBuilder[rdf.type]()("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#")(ops) {
// val langString = apply("langString") //todo: does not exist in ontology
// val nil = apply("nil")
// val typ = apply("type")
// val Alt = apply("Alt")
// val Bag = apply("Bag")
// val List = apply("List")
// val PlainLiteral = apply("PlainLiteral")
// val Property = apply("Property")
// val Seq = apply("Seq")
// val Statement = apply("Statement")
// val XMLLiteral = apply("XMLLiteral")
// val first = apply("first")
// val langRange = apply("langRange")
// val obj = apply("object")
// val predicate = apply("predicate")
// val rest = apply("rest")
// val subject = apply("subject")
// val `type` = apply("type")
// val value = apply("value")
//}
//
//object XSDPrefix {
// def apply[T <: RDFObj](implicit ops: RDFOps[Rdf]) = new XSDPrefix[Rdf](ops)
//}
//
//class XSDPrefix[T <: RDFObj](using val rdf: T)(using val ops: RDFOps[rdf.type])
// extends PrefixBuilder[rdf.type]("xsd", "http://www.w3.org/2001/XMLSchema#")(ops) {
// import ops._
//
// // http://www.w3.org/TR/owl-rdf-based-semantics
// // Table 3.3 Datatypes of the OWL 2 RDF-Based Semantics
//
// // http://www.w3.org/TR/owl2-syntax/
// // Table 3 Reserved VOcabulary of OWL 2 with Special Treatment
//
// val anyURI = apply("anyURI")
// val base64Binary = apply("base64Binary")
// val boolean = apply("boolean")
// val `true` = makeLiteral("true", boolean)
// val `false` = makeLiteral("false", boolean)
// val byte = apply("byte")
// val dateTime = apply("dateTime")
// val dateTimeStamp = apply("dateTimeStamp")
// val decimal = apply("decimal")
// val double = apply("double")
// val float = apply("float")
// val hexBinary = apply("hexBinary")
// val int = apply("int")
// val integer = apply("integer")
// val language = apply("language")
// val long = apply("long")
// val maxExclusive = apply("maxExclusive")
// val maxInclusive = apply("maxInclusive")
// val maxLength = apply("maxLength")
// val minExclusive = apply("minExclusive")
// val minInclusive = apply("minInclusive")
// val minLength = apply("minLength")
// val Name = apply("Name")
// val NCName = apply("NCName")
// val negativeInteger = apply("negativeInteger")
// val NMToken = apply("NMToken")
// val nonNegativeInteger = apply("nonNegativeInteger")
// val nonPositiveInteger = apply("nonPositiveInteger")
// val normalizedString = apply("normalizedString")
// val pattern = apply("pattern")
// val PlainLiteral = apply("PlainLiteral")
// val positiveInteger = apply("positiveInteger")
// val short = apply("short")
// val string = apply("string")
// val token = apply("token")
// val unsignedByte = apply("unsignedByte")
// val unsignedInt = apply("unsignedInt")
// val unsignedLong = apply("unsignedLong")
// val unsignedShort = apply("unsignedShort")
//}
//
//object DCPrefix {
// def apply[T <: RDFObj](using ops: RDFOps[T]) = new DCPrefix()
//}
//
//class DCPrefix[T <: RDFObj](using val rdf: T)(using val ops: RDFOps[rdf.type])
// extends PrefixBuilder[rdf.type]("dc", "http://purl.org/dc/elements/1.1/")(ops) {
// val language = apply("language")
//
//}
//
//object DCTPrefix {
// def apply[T <: RDFObj](implicit ops: RDFOps[T]) = new DCTPrefix()
//}
//
//class DCTPrefix[T <: RDFObj](using val rdf: T)(using val ops: RDFOps[rdf.type])
// extends PrefixBuilder[rdf.type]("dc", "http://purl.org/dc/terms/")(ops) {
// val title = apply("title")
//
//}
//
//object FOAFPrefix {
// def apply[T <: RDFObj](implicit ops: RDFOps[T]) = new FOAFPrefix()
//}
//
//class FOAFPrefix[T <: RDFObj](using val rdf: T)(using val ops: RDFOps[rdf.type])
// extends PrefixBuilder[rdf.type]("foaf", "http://xmlns.com/foaf/0.1/")(ops) {
// //todo: remove these relations as they don't exist in foaf
// val height = apply("height")
// val publication = apply("publication")
// val wants = apply("wants")
// val author = apply("author")
//
// //resources that actually exist in foaf
// val Agent = apply("Agent")
// val Document = apply("Document")
// val Group = apply("Group")
// val Image = apply("Image")
// val LabelProperty = apply("LabelProperty")
// val OnlineAccount = apply("OnlineAccount")
// val OnlineChatAccount = apply("OnlineChatAccount")
// val OnlineEcommerceAccount = apply("OnlineEcommerceAccount")
// val OnlineGamingAccount = apply("OnlineGamingAccount")
// val Organization = apply("Organization")
// val Person = apply("Person")
// val PersonalProfileDocument = apply("PersonalProfileDocument")
// val Project = apply("Project")
// val account = apply("account")
// val accountName = apply("accountName")
// val accountServiceHomepage = apply("accountServiceHomepage")
// val age = apply("age")
// val aimChatID = apply("aimChatID")
// val based_near = apply("based_near")
// val birthday = apply("birthday")
// val currentProject = apply("currentProject")
// val depiction = apply("depiction")
// val depicts = apply("depicts")
// val dnaChecksum = apply("dnaChecksum")
// val familyName = apply("familyName")
// val family_name = apply("family_name")
// val firstName = apply("firstName")
// val focus = apply("focus")
// val fundedBy = apply("fundedBy")
// val geekcode = apply("geekcode")
// val gender = apply("gender")
// val givenName = apply("givenName")
// val givenname = apply("givenname")
// val holdsAccount = apply("holdsAccount")
// val homepage = apply("homepage")
// val icqChatID = apply("icqChatID")
// val img = apply("img")
// val interest = apply("interest")
// val isPrimaryTopicOf = apply("isPrimaryTopicOf")
// val jabberID = apply("jabberID")
// val knows = apply("knows")
// val lastName = apply("lastName")
// val logo = apply("logo")
// val made = apply("made")
// val maker = apply("maker")
// val mbox = apply("mbox")
// val mbox_sha1sum = apply("mbox_sha1sum")
// val member = apply("member")
// val membershipClass = apply("membershipClass")
// val msnChatID = apply("msnChatID")
// val myersBriggs = apply("myersBriggs")
// val name = apply("name")
// val nick = apply("nick")
// val openid = apply("openid")
// val page = apply("page")
// val pastProject = apply("pastProject")
// val phone = apply("phone")
// val plan = apply("plan")
// val primaryTopic = apply("primaryTopic")
// val publications = apply("publications")
// val schoolHomepage = apply("schoolHomepage")
// val sha1 = apply("sha1")
// val skypeID = apply("skypeID")
// val status = apply("status")
// val surname = apply("surname")
// val theme = apply("theme")
// val thumbnail = apply("thumbnail")
// val tipjar = apply("tipjar")
// val title = apply("title")
// val topic = apply("topic")
// val topic_interest = apply("topic_interest")
// val weblog = apply("weblog")
// val workInfoHomepage = apply("workInfoHomepage")
// val workplaceHomepage = apply("workplaceHomepage")
// val yahooChatID = apply("yahooChatID")
//
//}
//
//object LDPPrefix {
// def apply[T <: RDFObj](implicit ops: RDFOps[T]) = new LDPPrefix(ops)
//}
//
//class LDPPrefix[T <: RDFObj](using val rdf: T)(using val ops: RDFOps[rdf.type])
// extends PrefixBuilder[rdf.type]("ldp", "http://www.w3.org/ns/ldp#")(ops) {
// val AggregateContainer = apply("AggregateContainer")
// val CompositeContainer = apply("CompositeContainer")
// val Container = apply("Container")
// val Page = apply("Page")
// val Resource = apply("Resource")
// val containerSortPredicates = apply("containerSortPredicates")
// val membershipPredicate = apply("membershipPredicate")
// val membershipSubject = apply("membershipSubject")
// val nextPage = apply("nextPage")
// val created = apply("created")
// val pageOf = apply("pageOf")
//}
//
//object IANALinkPrefix {
// def apply[T <: RDFObj](implicit ops: RDFOps[T]) = new IANALinkPrefix()
//}
//
///**
// * The Iana Link Relations are not linked data so these URLs are currently invented ones, and need
// * not reflect what may be used if ever such URIs are coined.
// */
//class IANALinkPrefix[T <: RDFObj](using val rdf: T)(using val ops: RDFOps[rdf.type])
// extends PrefixBuilder[rdf.type]("link", "http://www.iana.org/assignments/link-relations/#")(ops) {
// val about = apply("about")
// val acl = apply("acl") //needs to be registered
// val alternate = apply("alternate")
// val appendix = apply("appendix")
// val archives = apply("archives")
// val author = apply("author")
// val bookmark = apply("bookmark")
// val canonical = apply("canonical")
// val chapter = apply("chapter")
// val collection = apply("collection")
// val contents = apply("contents")
// val copyright = apply("copyright")
// val create_form = apply("create-form")
// val current = apply("current")
// val describedby = apply("describedby")
// val describes = apply("describes")
// val disclosure = apply("disclosure")
// val duplicate = apply("duplicate")
// val edit = apply("edit")
// val edit_form = apply("edit-form")
// val edit_media = apply("edit-media")
// val enclosure = apply("enclosure")
// val first = apply("first")
// val glossary = apply("glossary")
// val help = apply("help")
// val hosts = apply("hosts")
// val hub = apply("hub")
// val icon = apply("icon")
// val index = apply("index")
// val item = apply("item")
// val last = apply("last")
// val latest_version = apply("latest-version")
// val license = apply("license")
// val lrdd = apply("lrdd")
// val meta = apply("meta") //needs to be registered
// val monitor = apply("monitor")
// val monitor_group = apply("monitor-group")
// val next = apply("next")
// val next_archive = apply("next-archive")
// val nofollow = apply("nofollow")
// val noreferrer = apply("noreferrer")
// val payment = apply("payment")
// val predecessor_version = apply("predecessor-version")
// val prefetch = apply("prefetch")
// val prev = apply("prev")
// val prev_archive = apply("prev-archive")
// val preview = apply("preview")
// val previous = apply("previous")
// val privacy_policy = apply("privacy-policy")
// val profile = apply("profile")
// val related = apply("related")
// val replies = apply("replies")
// val search = apply("search")
// val section = apply("section")
// val self = apply("self")
// val service = apply("service")
// val start = apply("start")
// val stylesheet = apply("stylesheet")
// val subsection = apply("subsection")
// val successor_version = apply("successor-version")
// val tag = apply("tag")
// val terms_of_service = apply("terms-of-service")
// val tpe = apply("type")
// val up = apply("up")
// val version_history = apply("version-history")
// val via = apply("via")
// val working_copy = apply("working-copy")
// val working_copy_of = apply("working-copy-of")
//
//}
//
//trait CommonPrefixes[T <: RDFObj](using val rdf: T) { this: RDFOps[T] =>
//
// lazy val xsd = XSDPrefix()(this)
// lazy val rdf = RDFPrefix()(this)
//
//}
//
//object WebACLPrefix {
// def apply[T <: RDFObj](implicit ops: RDFOps[T]) = new WebACLPrefix(ops)
//}
//
//class WebACLPrefix[T <: RDFObj](using val rdf: T)(using val ops: RDFOps[rdf.type])
// extends PrefixBuilder[rdf.type]("acl", "http://www.w3.org/ns/auth/acl#")(ops) {
// val Authorization = apply("Authorization")
// val agent = apply("agent")
// val agentClass = apply("agentClass")
// val accessTo = apply("accessTo")
// val accessToClass = apply("accessToClass")
// val defaultForNew = apply("defaultForNew")
// val mode = apply("mode")
// val Access = apply("Access")
// val Read = apply("Read")
// val Write = apply("Write")
// val Append = apply("Append")
// val accessControl = apply("accessControl")
// val Control = apply("Control")
// val owner = apply("owner")
// val WebIDAgent = apply("WebIDAgent")
//
// //not officially supported:
// val include = apply("include")
// val regex = apply("regex")
//}
//
//object CertPrefix {
// def apply[T <: RDFObj](using ops: RDFOps[T]) = new CertPrefix()
//}
//
//class CertPrefix[T <: RDFObj](using val rdf: T)(using val ops: RDFOps[rdf.type])
// extends PrefixBuilder[rdf.type]("cert", "http://www.w3.org/ns/auth/cert#")(ops) {
// val key = apply("key")
// val RSAKey = apply("RSAKey")
// val RSAPublicKey = apply("RSAPublicKey")
// val exponent = apply("exponent")
// val modulus = apply("modulus")
//}
//
//object OWLPrefix {
// def apply[T <: RDFObj](using ops: RDFOps[T]) = new OWLPrefix()
//}
//
//class OWLPrefix[T <: RDFObj](using val rdf: T)(using val ops: RDFOps[rdf.type])
// extends PrefixBuilder[rdf.type]("owl", "http://www.w3.org/2002/07/owl#")(ops) {
//
// // http://www.w3.org/TR/owl2-rdf-based-semantics/
// // table 3.2: OWL 2 RDF-Based Vocabulary
//
// val AllDifferent = apply("AllDifferent")
// val AllDisjointClasses = apply("AllDisjointClasses")
// val AllDisjointProperties = apply("AllDisjointProperties")
// val allValuesFrom = apply("allValuesFrom")
// val annotatedProperty = apply("annotatedProperty")
// val annotatedSource = apply("annotatedSource")
// val annotatedTarget = apply("annotatedTarget")
// val Annotation = apply("Annotation")
// val AnnotationProperty = apply("AnnotationProperty")
// val assertionProperty = apply("assertionProperty")
// val AsymmetricProperty = apply("AsymmetricProperty")
// val Axiom = apply("Axiom")
// val backwardCompatibleWith = apply("backwardCompatibleWith")
// val bottomDataProperty = apply("bottomDataProperty")
// val bottomObjectProperty = apply("bottomObjectProperty")
// val cardinality = apply("cardinality")
// val Class = apply("Class")
// val complementOf = apply("complementOf")
// val DataRange = apply("DataRange")
// val datatypeComplementOf = apply("datatypeComplementOf")
// val DatatypeProperty = apply("DatatypeProperty")
// val deprecated = apply("deprecated")
// val DeprecatedClass = apply("DeprecatedClass")
// val DeprecatedProperty = apply("DeprecatedProperty")
// val differentFrom = apply("differentFrom")
// val disjointUnionOf = apply("disjointUnionOf")
// val disjointWith = apply("disjointWith")
// val distinctMembers = apply("distinctMembers")
// val equivalentClass = apply("equivalentClass")
// val equivalentProperty = apply("equivalentProperty")
// val FunctionalProperty = apply("FunctionalProperty")
// val hasKey = apply("hasKey")
// val hasSelf = apply("hasSelf")
// val hasValue = apply("hasValue")
// val imports = apply("imports")
// val incompatibleWith = apply("incompatibleWith")
// val intersectionOf = apply("intersectionOf")
// val InverseFunctionalProperty = apply("InverseFunctionalProperty")
// val inverseOf = apply("inverseOf")
// val IrreflexiveProperty = apply("IrreflexiveProperty")
// val maxCardinality = apply("maxCardinality")
// val maxQualifiedCardinality = apply("maxQualifiedCardinality")
// val members = apply("members")
// val minCardinality = apply("minCardinality")
// val minQualifiedCardinality = apply("minQualifiedCardinality")
// val NamedIndividual = apply("NamedIndividual")
// val NegativePropertyAssertion = apply("NegativePropertyAssertion")
// val Nothing = apply("Nothing")
// val ObjectProperty = apply("ObjectProperty")
// val onClass = apply("onClass")
// val onDataRange = apply("onDataRange")
// val onDatatype = apply("onDatatype")
// val oneOf = apply("oneOf")
// val onProperty = apply("onProperty")
// val onProperties = apply("onProperties")
// val Ontology = apply("Ontology")
// val OntologyProperty = apply("OntologyProperty")
// val priorVersion = apply("priorVersion")
// val propertyChainAxiom = apply("propertyChainAxiom")
// val propertyDisjointWith = apply("propertyDisjointWith")
// val qualifiedCardinality = apply("qualifiedCardinality")
// val ReflexiveProperty = apply("ReflexiveProperty")
// val Restriction = apply("Restriction")
// val sameAs = apply("sameAs")
// val someValuesFrom = apply("someValuesFrom")
// val sourceIndividual = apply("sourceIndividual")
// val SymmetricProperty = apply("SymmetricProperty")
// val targetIndividual = apply("targetIndividual")
// val targetValue = apply("targetValue")
// val Thing = apply("Thing")
// val topDataProperty = apply("topDataProperty")
// val topObjectProperty = apply("topObjectProperty")
// val TransitiveProperty = apply("TransitiveProperty")
// val unionOf = apply("unionOf")
// val versionInfo = apply("versionInfo")
// val versionIRI = apply("versionIRI")
// val withRestrictions = apply("withRestrictions")
//}