本文整理汇总了Python中Formatter.format方法的典型用法代码示例。如果您正苦于以下问题:Python Formatter.format方法的具体用法?Python Formatter.format怎么用?Python Formatter.format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Formatter
的用法示例。
在下文中一共展示了Formatter.format方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import Formatter [as 别名]
# 或者: from Formatter import format [as 别名]
def main():
f = open('data/person_foaf.n3')
fresnel_data = f.read()
fresnel = Fresnel( fresnel_data )
print "Created Fresnel Graph.."
rdf_graph = Graph()
print "Downloading resource.."
#f = open('data/Tim_Berners-Lee.rdf')
#rdf_graph.parse( file=f, format="xml")
#rdf_graph.parse(source="http://dbpedia.org/page/A._P._J._Abdul_Kalam")
#print "more..."
f = open('data/A._P._J._Abdul_Kalam.rdf')
rdf_graph.parse( file=f, format="xml")
#rdf_graph.parse(source="http://dbpedia.org/page/Tim_Berners-Lee")
for term in rdf_graph:
print term
print "Making selection.."
selector = Selector( fresnel , rdf_graph)
selector.select()
formatter = Formatter( selector )
formatter.format()
data = "<html>\n<head><link rel='stylesheet' type='text/css' href='style.css'></head>\n<body>\n"
for resource in formatter.result:
print resource.render()
data += resource.render()
data += "</body>\n</html>"
f = open('output/test.html', 'w')
f.write(data.encode('utf-8'))
示例2: tagAction
# 需要导入模块: import Formatter [as 别名]
# 或者: from Formatter import format [as 别名]
DATA_AMOUNT_PER_SEC = 250
TWO_SECS_DATA_AMOUNT = 2 * DATA_AMOUNT_PER_SEC
THREE_SECS_DATA_AMOUNT = 3 * DATA_AMOUNT_PER_SEC
FIVE_SECS_DATA_AMOUNT = 5 * DATA_AMOUNT_PER_SEC
def tagAction(channels, startTime, endTime, actionInterval, actingDuration):
doNothing = [[] if channel else None for channel in channels]
action = copy.deepcopy(doNothing)
actionDataAmount = int(actingDuration * DATA_AMOUNT_PER_SEC)
actionIntervalDataAmount = int(actionInterval * DATA_AMOUNT_PER_SEC)
for dataPtr in xrange(int(startTime * DATA_AMOUNT_PER_SEC) + 1, int(endTime * DATA_AMOUNT_PER_SEC), actionIntervalDataAmount):
for i, channel in enumerate(channels):
if channel:
action[i].extend(channel[dataPtr: dataPtr + actionDataAmount])
doNothing[i].extend(channel[dataPtr + actionDataAmount: dataPtr + actionIntervalDataAmount])
return doNothing, action
if __name__ == "__main__":
channelsWrap = Formatter.format({"step": 1, "wink": 1}, [1, 2, 3, 4])
winkDoNothing, wink = tagAction(channelsWrap["wink"][0], 10, 101, 5, 1)
stepDoNothing, leftStep = tagAction(channelsWrap["step"][0], 4.87, 100.87, 5, 0.85)
stepDoNothing2, rightStep = tagAction(channelsWrap["step"][0], 104.87, 200.87, 5, 0.85)
channelsWrap.clear()
channelsWrap["winkdonothing"] = [winkDoNothing]
channelsWrap["wink"] = [wink]
channelsWrap["stepdonothing"] = [stepDoNothing]
channelsWrap["leftstep"] = [leftStep]
channelsWrap["rightstep"] = [rightStep]
channelsWrap = Sampler.sampleChannelsWrap(channelsWrap, 2)
Formatter.writeDataWrap(channelsWrap, 3)
示例3: sampleChannelsStream
# 需要导入模块: import Formatter [as 别名]
# 或者: from Formatter import format [as 别名]
__author__ = 'maeglin89273'
import Formatter
DEFAULT_SAMPLING_RATE = 5
def sampleChannelsStream(channelData, samplingRate):
sampledData = [[] if channel else None for channel in channelData]
for (i, channelValues) in enumerate(zip(*filter(lambda channel: bool(channel), channelData))):
if i % samplingRate == 0:
for (j, channelNum) in enumerate((num for num in xrange(len(channelData)) if channelData[num])):
sampledData[channelNum].append(channelValues[j])
return sampledData
def sampleChannelsWrap(channelsWrap, samplingRate):
for category in channelsWrap:
for fileNum, channelData in enumerate(channelsWrap[category]):
sampledData = sampleChannelsStream(channelData, samplingRate)
channelsWrap[category][fileNum] = sampledData
return channelsWrap
if __name__ == "__main__":
channelsWrap = Formatter.format({"righthand": 4, "sleep": 1}, [1, 2, 3, 4, 8])
Formatter.writeDataWrap(sampleChannelsWrap(channelsWrap, DEFAULT_SAMPLING_RATE), 2)