当前位置: 首页>>代码示例>>Python>>正文


Python Graph.label方法代码示例

本文整理汇总了Python中rdflib.Graph.label方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.label方法的具体用法?Python Graph.label怎么用?Python Graph.label使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rdflib.Graph的用法示例。


在下文中一共展示了Graph.label方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: parse_owl

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import label [as 别名]
def parse_owl(url, id, annotype):
    """" Download and parse owl files to return a dictionary of annotation values,
    where the unique identifier is the key and the name is the value,
    and the version and date information for the owl file. """
    # change working directory to 'source-data'
    if not os.path.exists('source-data'):
        os.mkdir('source-data')
    os.chdir('source-data')
    anno_dict = {}
    version = None
    owl = Graph()
    owl.parse(get_data(url))
    try:
        ontology = [s for s in owl.subjects(RDF.type, OWL.Ontology)][0]
    except:
        print("No Ontology URI for {0}".format(url))
    ver = owl.value(ontology, OWL.versionIRI)
    if ver:  # 1st try getting version and date from versionIRI
        version = str(ver)
        pub_date = version.split('/')[-2]
    if not version:  # 2nd try getting version from versionInfo
        ver = owl.value(ontology, OWL.versionInfo)
        if ver:
            version = str(ver[0])
        pub_date = owl.value(ontology, DC.date)
    if not pub_date:  # last try getting date from Ontology comments
        for o in owl.objects(ontology, RDFS.comment):
            if str(o).startswith('Date:'):
                pub_date = str(o).split(':')[-1].strip()
                pub_date = datetime.datetime.strptime(pub_date, '%dth %B %Y')
                pub_date = pub_date.strftime('%Y-%m-%d')

    print(version)
    print(pub_date)
    if id == 'EFO':  # only using cell_lines from EFO, make list of Classes
        cell_lines = [q[0] for q in owl.query(
            'SELECT * WHERE {?s rdfs:subClassOf+ <http://www.ebi.ac.uk/efo/EFO_0000322>}')]
    for s in owl.subjects(RDF.type, OWL.Class):
        val = owl.label(s)
        term = str(s).split('/')[-1]
        obsolete = owl.value(s, OWL.deprecated)
        if val and term.startswith(id) and not obsolete:
            if id == 'EFO' and s not in cell_lines:
                continue
            else:
                anno_dict[term] = val
    os.chdir(os.pardir)
    return anno_dict, ver, pub_date
开发者ID:OpenBEL,项目名称:resource-generator,代码行数:50,代码来源:belanno.py

示例2: parse

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import label [as 别名]
 def parse(self):
     oboInOwl = Namespace("http://www.geneontology.org/formats/oboInOwl#")
     owl = Graph()
     owl.parse(self._url)
     for s in owl.subjects(RDF.type, OWL.Class):
         term_dict = {}
         pref_label = owl.label(s)
         term_id = str(s).split("/")[-1]
         dbxrefs = {str(x) for x in owl.objects(s, oboInOwl.hasDbXref)}
         synonyms = {x for x in owl.objects(s, oboInOwl.hasExactSynonym)}
         obsolete = owl.value(s, OWL.deprecated)
         alt_ids = {str(x) for x in owl.objects(s, oboInOwl.hasAlternativeId)}
         term_type = self.check_elem_type(s, owl)
         term_dict["name"] = pref_label
         term_dict["id"] = term_id
         term_dict["dbxrefs"] = dbxrefs
         term_dict["synonyms"] = synonyms
         term_dict["is_obsolete"] = obsolete
         term_dict["alt_ids"] = alt_ids
         if term_type:
             term_dict["term_type"] = term_type
         yield term_dict
开发者ID:nbargnesi,项目名称:resource-generator,代码行数:24,代码来源:parsers.py

示例3: get

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import label [as 别名]

#.........这里部分代码省略.........
						price_type = g.value(pinfo,GR.priceType)
						# Let's ne tolerant - accept "true", "True", and boolean:True
						# This is needed because we must expect missing datatypes
						decoration = '<span style="color:red">Today'
						
						is_list_price = str(is_list_price)
						if is_list_price.lower().startswith('true'): 
							price_info += 'List Price: ' # deprecated pattern, but still used by Yahoo
							decoration = "<span>"
						price_type = str(price_type)	
						if price_type.upper().startswith('SRP'):
							price_info += 'Suggested Retail Price: ' # correct pattern
							decoration = "<span>"
																		
						# Is it a point price ?
						if price != None: 
							price_info += "%s %s %.2f"% (decoration,currency,float(price.toPython()))
							
						# Is it a price range?
						# Note that due to reasoning, a point price may be expanded to a price range with min=max
						# Thus, we have to check for the point price first
						else:
							if price_min != None:
								price_info += "%s from: %s %.2f"% (decoration,currency, float(str(price_min))) # expect bad markup
								if price_max != None:
									price_info += " to "
									price_info += "%.2f" % float(str(price_max)) # expect bad markup
							elif price_max != None:
								price_info += "%s %s %.2f or less"% (decoration,currency, float(str(price_max))) # expect bad markup
						price_info += '</span>'
														
					# Convert payment info into string
					for p_option in g.objects(None,GR.acceptedPaymentMethods):
						method = g.label(p_option)
						if len(payments)>0:
							payments += ", "
						pos = method.find(' (') 
						if pos>-1:
							method = method[:pos]
						payments += method

					# Convert Opening hour info into string
					# TBD: Order by day of week
					delimiter = ""					
					for openinghrs in g.subjects(RDF.type,GR.OpeningHoursSpecification):
						openingspecs += delimiter
						opens = g.value(openinghrs,GR.opens)
						closes = g.value(openinghrs,GR.closes)	
						daysofweek = g.objects(openinghrs,GR.hasOpeningHoursDayOfWeek)
						for day in daysofweek:
							dayname = g.label(day)
							dayname = dayname[:3]
							openingspecs += str(dayname)+", "
						openingspecs = openingspecs[:len(openingspecs)-2]	
						openingspecs +=(": "+opens[:5]+"-"+closes[:5])
						delimiter = ", "
				else:
					logging.info("***** FALSE %s, %s -- ignored" % (item['url'], h))
					
				if len(price_info)>0 or len(payments)>0 or len(openingspecs)>0:
					hasGR = True
					logging.info("==>GR>== Found GoodRelations meta-data at %s" % item['url'])
										
				if hasRDF:					
					pyrdfa = PYRDFA_URI % item['url']
					ode = ODE_URI % item['url']
开发者ID:mfhepp,项目名称:igoogr,代码行数:70,代码来源:main.py


注:本文中的rdflib.Graph.label方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。