def __init__(self, alias): # setup self.alias = alias parsetype = alias.split("/")[1] self.parser = LegalRef({ 'SFS': LegalRef.LAGRUM, 'Short': LegalRef.KORTLAGRUM, 'DV': LegalRef.RATTSFALL, 'Regpubl': LegalRef.FORARBETEN, 'EGLag': LegalRef.EULAGSTIFTNING, 'ECJ': LegalRef.EURATTSFALL }[parsetype]) # this particular test method is set up to use lagen.nu style # URIs because the canonical URIs are significantly different. dirname = os.path.dirname(__file__) basedir = dirname + "/../" space = basedir + "lagen/nu/res/uri/swedishlegalsource.space.ttl" slugs = basedir + "lagen/nu/res/uri/swedishlegalsource.slugs.ttl" extra = [ basedir + "lagen/nu/res/extra/swedishlegalsource.ttl", basedir + "lagen/nu/res/extra/sfs.ttl" ] cfg = Graph().parse(space, format="turtle").parse(slugs, format="turtle") self.metadata = Graph() for ttl in extra: self.metadata.parse(ttl, format="turtle") COIN = Namespace("http://purl.org/court/def/2009/coin#") # select correct URI for the URISpace definition by # finding a single coin:URISpace object spaceuri = cfg.value(predicate=RDF.type, object=COIN.URISpace) self.minter = URIMinter(cfg, spaceuri)
def sameas_minter(self): # make a resourceloader that only loads resource from # superclasses, not this actual class. This'll make it # look in ferenda/sources/legal/se/res, not lagen/nu/res. loadpath = ResourceLoader.make_loadpath(self) if "lagen/nu/" in loadpath[0]: loadpath = loadpath[1:] rl = ResourceLoader(*loadpath) spacefile = rl.filename("uri/swedishlegalsource.space.ttl") # print("sameas: Loading URISpace from %s" % spacefile) self.log.debug("Loading URISpace from %s" % spacefile) with open(spacefile) as space: cfg = Graph().parse(space, format="turtle") # slugs contains space:abbrSlug, but space contains # urispace:abbrSlug... We do a little translation src = URIRef("http://rinfo.lagrummet.se/sys/uri/space#abbrSlug") dst = URIRef("https://lagen.nu/sys/uri/space#abbrSlug") for (s, p, o) in cfg: if o == src: # print("Translating %s %s :abbrSlug" % (s.n3(), p.n3())) cfg.remove((s, p, o)) cfg.add((s, p, dst)) elif s == dst: # print("Translating :abbrSlug %s %s" % (p.n3(), o.n3())) cfg.remove((s, p, o)) cfg.add((dst, p, o)) slugsfile = self.resourceloader.filename("uri/swedishlegalsource.slugs.ttl") # self.log.debug("sameas: Loading slugs from %s" % slugsfile) with open(slugsfile) as slugs: cfg.parse(slugs, format="turtle") COIN = Namespace("http://purl.org/court/def/2009/coin#") # select correct URI for the URISpace definition by # finding a single coin:URISpace object spaceuri = cfg.value(predicate=RDF.type, object=COIN.URISpace) return URIMinter(cfg, spaceuri)
def setUpClass(cls): with codecs.open(cls.spacefile, encoding="utf-8") as space: with codecs.open(cls.slugsfile, encoding="utf-8") as slugs: cfg = rdflib.Graph().parse(space, format="turtle").parse(slugs, format="turtle") COIN = rdflib.Namespace("http://purl.org/court/def/2009/coin#") # select correct URI for the URISpace definition by # finding a single coin:URISpace object spaceuri = cfg.value(predicate=rdflib.RDF.type, object=COIN.URISpace) cls.minter = URIMinter(cfg, spaceuri)
def minter(self): # print("%s (%s) loading minter" % (self.alias, id(self))) filename = self.resourceloader.filename spacefile = filename("uri/swedishlegalsource.space.ttl") slugsfile = filename("uri/swedishlegalsource.slugs.ttl") self.log.debug("Loading URISpace from %s" % spacefile) # print("Loading URISpace from %s" % spacefile) # print("Loading Slugs from %s" % slugsfile) cfg = Graph().parse(spacefile, format="turtle").parse(slugsfile, format="turtle") COIN = Namespace("http://purl.org/court/def/2009/coin#") # select correct URI for the URISpace definition by # finding a single coin:URISpace object spaceuri = cfg.value(predicate=RDF.type, object=COIN.URISpace) return URIMinter(cfg, spaceuri)
def coinstruct_from_graph(graph, subject, minter=None): if not minter: configgraph = Graph() # FIXME: The configgraph should only be loaded once, but be # configurable ie load the correct COIN n3 config configgraph.parse( "ferenda/sources/legal/se/res/uri/swedishlegalsource.space.ttl", format="turtle") configgraph.parse( "ferenda/sources/legal/se/res/uri/swedishlegalsource.slugs.ttl", format="turtle") minter = URIMinter(configgraph, URIRef("http://rinfo.lagrummet.se/sys/uri/space#")) result = minter.space.coin_uri(graph.resource(subject)) return result # only return the "best" ie most prioritized template
def setUpClass(cls): # this particular test method is set up to use lagen.nu style # URIs because the canonical URIs are significantly different. space = "lagen/nu/res/uri/swedishlegalsource.space.ttl" slugs = "lagen/nu/res/uri/swedishlegalsource.slugs.ttl" extra = [ "lagen/nu/res/extra/swedishlegalsource.ttl", "lagen/nu/res/extra/sfs.ttl" ] cfg = Graph().parse(space, format="turtle").parse(slugs, format="turtle") cls.metadata = Graph() for ttl in extra: cls.metadata.parse(ttl, format="turtle") COIN = Namespace("http://purl.org/court/def/2009/coin#") # select correct URI for the URISpace definition by # finding a single coin:URISpace object spaceuri = cfg.value(predicate=RDF.type, object=COIN.URISpace) cls.minter = URIMinter(cfg, spaceuri)