Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | 2x 2x 2855x 2855x 1429x 1429x 2x 2x 192x 192x 96x 96x 2x 2x 2x 1x 1x 2x 2x 2x 3x 2x 1x 2x 3x 3x 1x 2x 1x 1x 15x 15x 15x 3x 3x 3x 3x 15x 8x 8x 8x 8x 14x 3x 3x 14x 7x 7x 2x 1x 1x 7x 6x 6x 6x 9x 9x 9x 9x 5x 9x 9x 9x 9x 4x 8x 8x 4x 8x 8x 1x 3x 2x 1x 3x 2x 2x 2x 1x 1x 3x 10x 10x 7x 3x | import { ResourceRepository } from "./resource-repository";
import { rdf, skos } from "../ontologies";
import { dataFactory } from "./data-factory";
export class ConceptRepository extends ResourceRepository {
/**
* Get all concepts.
* @param graphUris URIs of the graphs to search for concepts.
* @returns An iterator of URIs of all concepts.
*/
*getConcepts(graphUris: string | string[] | undefined): IterableIterator<string> {
const yielded = new Set<string>();
for (let q of this.store.matchAll(graphUris, null, rdf.type, skos.Concept)) {
const s = q.subject;
if (!yielded.has(s.value)) {
yielded.add(s.value);
yield s.value;
}
}
}
/**
* Get all concept schemes.
* @param graphUris URIs of the graphs to search for concepts.
* @returns An iterator of URIs of all concept schemes.
*/
*getConceptSchemes(graphUris: string | string[] | undefined): IterableIterator<string> {
const yielded = new Set<string>();
for (let q of this.store.matchAll(graphUris, null, rdf.type, skos.ConceptScheme)) {
const s = q.subject;
if (!yielded.has(s.value)) {
yielded.add(s.value);
yield s.value;
}
}
}
/**
* Get all collections.
* @param graphUris URI of the graphs to search for collections.
* @returns An iterator of URIs of all collections.
*/
*getCollections(graphUris: string | string[] | undefined): IterableIterator<string> {
const yielded = new Set<string>();
for (let q of this.store.matchAll(graphUris, null, rdf.type, skos.Collection)) {
const s = q.subject;
if (!yielded.has(s.value)) {
yielded.add(s.value);
yield s.value;
}
}
for (let q of this.store.matchAll(graphUris, null, rdf.type, skos.OrderedCollection)) {
const s = q.subject;
if (!yielded.has(s.value)) {
yielded.add(s.value);
yield s.value;
}
}
}
/**
* Get the members of a collection. This includes both `skos:member` and `skos:memberList` properties.
* @param graphUris URI of the graphs to search for collections.
* @param collectionUri URI of a collection.
* @returns An array of URIs of the members of the collection.
*/
getCollectionMembers(graphUris: string | string[] | undefined, collectionUri: string): string[] {
const s = dataFactory.namedNode(collectionUri);
let result: string[] = [];
for (let q of this.store.matchAll(graphUris, s, skos.member, null)) {
result.push(q.object.value);
}
for (let q of this.store.matchAll(graphUris, s, skos.memberList, null)) {
result = [...result, ...this.store.getListItems(graphUris, q.object.value)];
}
return result;
}
/**
* Get the members of a collection. This includes both `skos:member` and `skos:memberList` properties.
* @param graphUris URI of the graphs to search for collections.
* @param collectionUri URI of a collection.
* @returns An array of URIs of the members of the collection.
*/
hasCollectionMembers(graphUris: string | string[] | undefined, collectionUri: string): boolean {
const s = dataFactory.namedNode(collectionUri);
for (let _ of this.store.matchAll(graphUris, s, skos.member, null)) {
return true;
}
for (let _ of this.store.matchAll(graphUris, s, skos.memberList, null)) {
return true;
}
return false;
}
/**
* Indicates whether a collection is an ordered collection.
* @param graphUris URI of the graphs to search for collections.
* @param collectionUri URI of a collection.
* @returns `true` if the collection is an ordered collection, `false` otherwise.
*/
isOrderedCollection(graphUris: string | string[] | undefined, collectionUri: string): boolean {
const s = dataFactory.namedNode(collectionUri);
for (let _ of this.store.matchAll(graphUris, s, rdf.type, skos.OrderedCollection)) {
return true;
}
return false;
}
/**
* Get all broader concepts of a concept scheme.
* @param graphUris URIs of the graphs to search for concepts.
* @param subjectUri URI of a concept scheme.
*/
*getBroaderConcepts(graphUris: string | string[] | undefined, subjectUri: string): IterableIterator<string> {
const yielded = new Set<string>();
const s = dataFactory.namedNode(subjectUri);
for (let q of this.store.matchAll(graphUris, null, skos.hasTopConcept, s)) {
const s = q.subject;
Eif (!yielded.has(s.value)) {
yielded.add(s.value);
yield s.value;
}
}
for (let q of this.store.matchAll(graphUris, null, skos.narrower, s)) {
const s = q.subject;
Eif (!yielded.has(s.value)) {
yielded.add(s.value);
yield s.value;
}
}
for (let q of this.store.matchAll(graphUris, s, skos.topConceptOf, null)) {
const o = q.object;
Iif (!yielded.has(o.value)) {
yielded.add(o.value);
yield o.value;
}
}
for (let q of this.store.matchAll(graphUris, s, skos.broader, null)) {
const o = q.object;
Iif (!yielded.has(o.value)) {
yielded.add(o.value);
yield o.value;
}
}
}
/**
* Indicates whether a concept has broader concepts.
* @param graphUris URIs of the graphs to search for concepts.
* @param subjectUri URI of a concept.
*/
hasBroaderConcepts(graphUris: string | string[] | undefined, subjectUri: string): boolean {
for(const _ of this.getBroaderConcepts(graphUris, subjectUri)) {
return true;
}
return false;
}
/**
* Get all narrower concepts of a concept or top concepts of a concept scheme.
* @param graphUris URIs of the graphs to search for concepts.
* @param subjectUri URI of a concept or concept scheme.
*/
*getNarrowerConcepts(graphUris: string | string[] | undefined, subjectUri?: string): IterableIterator<string> {
if (subjectUri) {
const yielded = new Set<string>();
const s = dataFactory.namedNode(subjectUri);
for (let q of this.store.matchAll(graphUris, s, skos.hasTopConcept, null)) {
const o = q.object;
Eif (!yielded.has(o.value)) {
yielded.add(o.value);
yield o.value;
}
}
for (let q of this.store.matchAll(graphUris, s, skos.narrower, null)) {
const o = q.object;
Eif (!yielded.has(o.value)) {
yielded.add(o.value);
yield o.value;
}
}
for (let q of this.store.matchAll(graphUris, null, skos.topConceptOf, s)) {
const s = q.subject;
Iif (!yielded.has(s.value)) {
yielded.add(s.value);
yield s.value;
}
}
for (let q of this.store.matchAll(graphUris, null, skos.broader, s)) {
const s = q.subject;
Iif (!yielded.has(s.value)) {
yielded.add(s.value);
yield s.value;
}
}
} else {
yield* this.getConceptSchemes(graphUris);
}
}
/**
* Indicates whether a concept has narrower concepts.
* @param graphUris URIs of the graphs to search for concepts.
* @param subjectUri URI of a concept.
*/
hasNarrowerConcepts(graphUris: string | string[] | undefined, subjectUri: string): boolean {
for(const _ of this.getNarrowerConcepts(graphUris, subjectUri)) {
return true;
}
return false;
}
/**
* Indicates whether a concept is a narrower concept of another concept.
* @param graphUris URIs of the graphs to search for concepts.
* @param subjectUri URI of a concept.
* @param broaderUri URI of a broader concept.
* @returns `true` if the concept is a narrower concept of the broader concept, `false` otherwise.
*/
isNarrowerConceptOf(graphUris: string | string[] | undefined, subjectUri: string, broaderUri: string): boolean {
return this.getConceptSchemePath(graphUris, subjectUri).includes(broaderUri);
}
/**
* Indicates whether a subject is a concept scheme.
* @param graphUris URIs of the graphs to search for concepts.
* @param subjectUri URI of a subject.
* @returns `true` if the subject is a concept scheme, `false` otherwise.
*/
isConceptScheme(graphUris: string | string[] | undefined, subjectUri: string): boolean {
Eif (subjectUri) {
const s = dataFactory.namedNode(subjectUri);
for (let _ of this.store.matchAll(graphUris, s, rdf.type, skos.ConceptScheme)) {
return true;
}
}
return false;
}
/**
* Get all broader concepts up to and including a concept scheme.
* @param graphUris URIs of the graphs to search for concepts.
* @param subjectUri URI of a concept.
*/
getConceptSchemePath(graphUris: string | string[] | undefined, subjectUri: string): string[] {
return this._getConceptSchemePath(graphUris, subjectUri, [], new Set<string>());
}
/**
* Recursively find the first path from a given class to a root class.
* @param subjectUri URI of a class.
* @param path The current class path.
* @param backtrack Set of URIs that have already been visited.
* @returns The first path that is found from the given class to a root class.
*/
private _getConceptSchemePath(graphUris: string | string[] | undefined, subjectUri: string, path: string[], backtrack: Set<string>): string[] {
const broaderConcepts = [...this.getBroaderConcepts(graphUris, subjectUri)];
for (let o of broaderConcepts.filter(o => !backtrack.has(o))) {
return this._getConceptSchemePath(graphUris, o, [...path, o], backtrack);
}
return path;
}
} |