Skip to content

Commit bcf21b1

Browse files
committed
changeUriprefix return identity map
1 parent 64c17d7 commit bcf21b1

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

SBOLTestSuite

Submodule SBOLTestSuite updated 331 files

sbolgraph/Graph.ts

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ export default class Graph {
6666
const matches = this.match(s, p, o)
6767

6868
if(matches.length > 1) {
69+
console.error('results:')
70+
console.dir(matches)
6971
throw new Error('Got more than one result for matchOne { ' + [s, p, o].join(', ') + ' }')
7072
}
7173

sbolgraph/SBOLXGraph.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ export default class SBOLXGraph extends Graph {
518518

519519
}
520520

521-
changeURIPrefix(newPrefix:string) {
521+
changeURIPrefix(newPrefix:string):Map<string,string> {
522522

523523
let topLevels = new Set([
524524
Types.SBOLX.Collection,
@@ -530,7 +530,7 @@ export default class SBOLXGraph extends Graph {
530530
Types.Prov.Activity
531531
])
532532

533-
changeURIPrefix(this, topLevels, newPrefix)
533+
return changeURIPrefix(this, topLevels, newPrefix)
534534

535535
}
536536

sbolgraph/changeURIPrefix.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ import rdf = require('rdf-ext')
44
import RdfGraphArray = require('rdf-graph-array')
55
import { Predicates } from 'bioterms'
66

7-
export default function changeURIPrefix(graph:Graph, topLevels:Set<string>, newPrefix:string) {
7+
export default function changeURIPrefix(graph:Graph, topLevels:Set<string>, newPrefix:string):Map<string,string> {
88

99
let triples = graph.graph._graph
1010

1111
let newGraph = new RdfGraphArray.Graph([])
1212

1313
let prefixes = new Set()
1414

15+
let identityMap = new Map()
16+
1517
for(let triple of triples) {
1618

1719
if(triple.predicate.nominalValue === Predicates.a) {
@@ -35,7 +37,9 @@ export default function changeURIPrefix(graph:Graph, topLevels:Set<string>, newP
3537

3638
for(let prefix of prefixes) {
3739
if(subject.nominalValue.indexOf(prefix) === 0) {
38-
subject = rdf.createNamedNode(newPrefix + subject.nominalValue.slice(prefix.length))
40+
let newSubject = rdf.createNamedNode(newPrefix + subject.nominalValue.slice(prefix.length))
41+
identityMap.set(subject.nominalValue, newSubject.nominalValue)
42+
subject = newSubject
3943
matched = true
4044
break
4145
}
@@ -49,7 +53,9 @@ export default function changeURIPrefix(graph:Graph, topLevels:Set<string>, newP
4953
if(object.interfaceName === 'NamedNode') {
5054
for(let prefix of prefixes) {
5155
if(object.nominalValue.indexOf(prefix) === 0) {
52-
object = rdf.createNamedNode(newPrefix + object.nominalValue.slice(prefix.length))
56+
let newObject = rdf.createNamedNode(newPrefix + object.nominalValue.slice(prefix.length))
57+
identityMap.set(object.nominalValue, newObject.nominalValue)
58+
object = newObject
5359
break
5460
}
5561
}
@@ -63,6 +69,8 @@ export default function changeURIPrefix(graph:Graph, topLevels:Set<string>, newP
6369

6470
graph.graph = newGraph
6571

72+
return identityMap
73+
6674
// TODO currently only works for compliant URIs
6775
//
6876
function prefix(uri:string) {

0 commit comments

Comments
 (0)