-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJSON-LD.types.ps1xml
More file actions
147 lines (124 loc) · 3.55 KB
/
JSON-LD.types.ps1xml
File metadata and controls
147 lines (124 loc) · 3.55 KB
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
<!-- Generated with EZOut 2.0.6: Install-Module EZOut or https://github.com/StartAutomating/EZOut -->
<Types>
<Type>
<Name>application/ld+json</Name>
<Members>
<ScriptMethod>
<Name>GetJsonSchema</Name>
<Script>
param($graph = $this)
if (-not $graph.'@graph') {
if ($graph.'@context' -is [string] -and
$graph.'@type' -is [string]) {
$gotGraph = Get-JsonLD -Url (
$graph.'@context', $graph.'@type' -join '/' -replace '^http:', 'https:'
)
if ($gotGraph.'@graph') {
$graph = $gotGraph
}
}
}
if (-not $graph.'@graph') { return }
$graphTypes = $graph.'@graph' | Group-Object '@type' -AsHashTable
$classes = $graphTypes['rdfs:class']
if (-not $classes) {
return
}
$baseType = $classes |
Where-Object 'rdfs:label' -eq 'thing'
if (-not $baseType) {
return
}
$ClassHierarchy = @(
$baseType
do {
$parentType = $classes |
Where-Object {
$_.'rdfs:subClassOf'.'@id' -eq $baseType.'@id'
}
if ($parentType) {
$parentType
$baseType = $parentType
}
} while ($parentType)
)
if (-not $ClassHierarchy) { return }
$classInfo = $ClassHierarchy[-1]
$jsonSchema = [Ordered]@{
'$id' = "`$$($classInfo.'@id' -replace 'schema:', 'schema.org/')"
title = $($classInfo.'@id' -replace 'schema:', 'https://schema.org/')
description = $classInfo.'rdfs:comment'
properties = [Ordered]@{}
}
foreach ($rdfProperty in $graphTypes['rdf:property']) {
$propertyInfo = [Ordered]@{}
switch -regex ($rdfProperty.'@id') {
'(?>date|time)$' {
$propertyInfo['type'] = 'string'
$propertyInfo['format'] = 'date-time'
}
'url$' {
$propertyInfo['type'] = 'string'
$propertyInfo['format'] = 'url'
}
'(?>name|description)$' {
$propertyInfo['type'] = 'string'
}
default {
$propertyInfo['type'] = 'object'
}
}
if (@($rdfProperty.'schema:rangeIncludes').Count -eq 1) {
switch ($rdfProperty.'schema:rangeIncludes') {
schema:Boolean {
$propertyInfo['type'] = 'boolean'
}
schema:Integer {
$propertyInfo['type'] = 'integer'
}
schema:Number {
$propertyInfo['type'] = 'number'
}
}
}
if ($rdfProperty.'rdfs:comment') {
$propertyInfo['description'] = $rdfProperty.'rdfs:comment'
}
$propertyName = $rdfProperty.'@id' -replace '^schema:'
$jsonSchema.properties[$propertyName] = $propertyInfo
}
$jsonSchema
</Script>
</ScriptMethod>
<ScriptMethod>
<Name>GetLexicon</Name>
<Script>
param($graph = $this)
$jsonSchema = $this.GetJsonSchema($graph)
if (-not $jsonSchema.'$id') {
throw "Missing $jsonSchema.$id"
return
}
$domain, $relativePath = $jsonSchema.'$id' -replace '^$' -split '/'
if (-not $domain) { return}
if (-not $relativePath ) { return }
$domain = @($domain -split '\.')
[Array]::Reverse($domain)
$nsid = $domain, $relativePath -join '.'
$jsonSchema.psobject.properties.Remove('$id')
[Ordered]@{
lexicon = 1
id = $nsid
defs = [Ordered]@{
main = [Ordered]@{
type = 'record'
description = $jsonSchema.description
record = $jsonSchema
}
}
}
</Script>
</ScriptMethod>
</Members>
</Type>
</Types>