本文整理汇总了Python中rdflib.graph.Graph.preferredLabel方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.preferredLabel方法的具体用法?Python Graph.preferredLabel怎么用?Python Graph.preferredLabel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rdflib.graph.Graph
的用法示例。
在下文中一共展示了Graph.preferredLabel方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: write_mappings
# 需要导入模块: from rdflib.graph import Graph [as 别名]
# 或者: from rdflib.graph.Graph import preferredLabel [as 别名]
def write_mappings():
# Include all pairs:
# ll = pair_association(unique_pairs, loglike)
# Only pairs with frequency >= 5:
unique_pars_5 = np.array([a.split('!') for a, b in pc.items() if b >= 5])
ll = pair_association(unique_pars_5, loglike)
print 'Write mappings'
lls = sorted(ll.items(), key=lambda x: x[1])
ww = np.array(ll.values())
mn = ww.mean()
print "- Mean LL is {:2f}".format(mn)
print "- {:.2f} % is >= mean LL".format(float(ww[ww >= mn].shape[0]) / ww.shape[0])
print "- {:.2f} % is < mean LL".format(float(ww[ww < mn].shape[0]) / ww.shape[0])
# Whether to lookup DDC labels and add them to the mapping sheet
addDdcLabels = False
if addDdcLabels:
# Load WebDewey data
g = Graph()
for x in glob('../../webdewey/DDK23/*.ttl'):
print x
g.load(x, format='turtle')
fsj = re.compile('.*\(Form\)')
with open('mappings.csv', 'w') as f:
writer = csv.writer(f, delimiter='\t')
for x in lls[::-1]:
if x[1] < mn:
break
q = x[0].split('!', 1)
if fsj.match(q[0]): # Utelat form
continue
if addDdcLabels:
lab = g.preferredLabel(URIRef('http://dewey.info/class/' + q[1] + '/e23/'), labelProperties=[SKOS.prefLabel, SKOS.altLabel])
if len(lab) != 0:
lab = lab[0][1].value
else:
lab = '(no label)'
# Term, Dewey, Dewey Caption, Loglike
writer.writerow([q[0], q[1], lab.encode('utf-8'), x[1]])
else:
# Term, Dewey, Loglike
writer.writerow([q[0], q[1], x[1]])
示例2: load
# 需要导入模块: from rdflib.graph import Graph [as 别名]
# 或者: from rdflib.graph.Graph import preferredLabel [as 别名]
def load(self, filename):
"""
Note: This loader only loads categories and mappings
"""
graph = Graph()
graph.load(filename, format=self.extFromFilename(filename))
logger.info('Read %d triples from %s', len(graph), filename)
skosify.infer.skos_symmetric_mappings(graph, related=False)
# Load mappings
n_mappings = 0
n_memberships = 0
for tr in graph.triples_choices((None, [SKOS.exactMatch, SKOS.closeMatch, SKOS.broadMatch, SKOS.narrowMatch, SKOS.relatedMatch], None)):
source_concept = tr[0]
res_id = self.vocabulary.id_from_uri(source_concept)
if res_id is not None:
shortName = str(tr[1]).split('#')[1]
try:
self.vocabulary.resources[res_id].add('mappings.%s' % shortName, str(tr[2]))
n_mappings += 1
except KeyError:
logger.warning('Concept not found: %s', res_id)
# Load categories
for tr in graph.triples((None, RDF.type, UOC.Category)):
cat_lab = graph.preferredLabel(tr[0], lang='nb')[0][1].value
cat_id = '' + tr[0]
cat = Concept().set_type('Category')
cat.set('id', cat_id)
cat.set('prefLabel.nb', Label(cat_lab))
self.vocabulary.resources.load([cat])
for tr2 in graph.triples((tr[0], SKOS.member, None)):
uri = str(tr2[2])
res_id = self.vocabulary.id_from_uri(uri)
if res_id is not None:
try:
self.vocabulary.resources[res_id].add('memberOf', cat_id)
n_memberships += 1
except KeyError:
logger.warning('Concept not found: %s', res_id)
# Load number of ccmapper mapping candidates
for tr in graph.triples((None, LOCAL.ccmapperCandidates, None)):
source_concept = tr[0]
res_id = self.vocabulary.id_from_uri(source_concept)
if res_id is not None:
shortName = str(tr[1]).split('#')[1]
try:
self.vocabulary.resources[res_id].set('ccmapperCandidates', int(tr[2]))
except KeyError:
logger.warning('Concept not found: %s', res_id)
# Load ccmapper mapping state
for tr in graph.triples((None, LOCAL.ccmapperState, None)):
source_concept = tr[0]
res_id = self.vocabulary.id_from_uri(source_concept)
if res_id is not None:
shortName = str(tr[1]).split('#')[1]
try:
self.vocabulary.resources[res_id].set('ccmapperState', tr[2])
except KeyError:
logger.warning('Concept not found: %s', res_id)
logger.info('Loaded %d mappings and %d category memberships from %s', n_mappings, n_memberships, filename)