本文整理汇总了Python中Core.IdSet.IdSet类的典型用法代码示例。如果您正苦于以下问题:Python IdSet类的具体用法?Python IdSet怎么用?Python IdSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IdSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, style="trigger_features:typed:directed:no_linear:entities:genia_limits:noMasking:maxFeatures", length=None, types=[], featureSet=None, classSet=None):
# reset style regardless of input
style="trigger_features:typed:directed:no_linear:entities:genia_limits:noMasking:maxFeatures"
if featureSet == None:
featureSet = IdSet()
if classSet == None:
classSet = IdSet(1)
else:
classSet = classSet
assert( classSet.getId("neg") == 1 )
ExampleBuilder.__init__(self, classSet=classSet, featureSet=featureSet)
self.styles = self.getParameters(style, ["trigger_features","typed","directed","no_linear","entities","genia_limits",
"noAnnType", "noMasking", "maxFeatures", "no_merge", "disable_entity_features",
"disable_single_element_features", "disable_ngram_features", "disable_path_edge_features"])
self.multiEdgeFeatureBuilder = MultiEdgeFeatureBuilder(self.featureSet)
self.multiEdgeFeatureBuilder.noAnnType = self.styles["noAnnType"]
self.multiEdgeFeatureBuilder.maskNamedEntities = not self.styles["noMasking"]
self.multiEdgeFeatureBuilder.maximum = self.styles["maxFeatures"]
self.tokenFeatureBuilder = TokenFeatureBuilder(self.featureSet)
self.pathLengths = length
assert(self.pathLengths == None)
self.types = types
self.triggerFeatureBuilder = TriggerFeatureBuilder(self.featureSet)
self.triggerFeatureBuilder.useNonNameEntities = True
示例2: __init__
def __init__(self, examples, predictions=None, classSet=None):
if type(classSet) == types.StringType: # class names are in file
classSet = IdSet(filename=classSet)
if type(predictions) == types.StringType: # predictions are in file
predictions = ExampleUtils.loadPredictions(predictions)
if type(examples) == types.StringType: # examples are in file
examples = ExampleUtils.readExamples(examples, False)
self.classSet = classSet
# define class ids in alphabetical order
self.classSet = classSet
if classSet != None:
classNames = sorted(classSet.Ids.keys())
else:
classNames = []
# make an ordered list of class ids
self.classes = []
for className in classNames:
self.classes.append(classSet.getId(className))
# create data structures for per-class evaluation
self.dataByClass = {}
for cls in self.classes:
self.dataByClass[cls] = EvaluationData()
# hack for unnamed classes
if len(self.dataByClass) == 0:
self.dataByClass[1] = EvaluationData()
self.dataByClass[2] = EvaluationData()
#self.untypedUndirected = None
self.untypedCurrentMajorId = None
self.untypedPredictionQueue = []
self.untypedUndirected = EvaluationData()
#self.AUC = None
if predictions != None:
self._calculate(examples, predictions)
示例3: __init__
def __init__(self, style=None, length=None, types=[], featureSet=None, classSet=None):
# reset style regardless of input
#style="trigger_features:typed:directed:no_linear:entities:genia_limits:noMasking:maxFeatures"
if featureSet == None:
featureSet = IdSet()
if classSet == None:
classSet = IdSet(1)
else:
classSet = classSet
assert( classSet.getId("neg") == 1 )
ExampleBuilder.__init__(self, classSet=classSet, featureSet=featureSet)
defaultNone = ["binary", "trigger_features","typed","directed","no_linear","entities","genia_limits",
"noAnnType", "noMasking", "maxFeatures", "no_merge", "disable_entity_features",
"disable_single_element_features", "disable_ngram_features", "disable_path_edge_features"]
defaultParameters = {}
for name in defaultNone:
defaultParameters[name] = None
defaultParameters["keep_intersentence"] = False
defaultParameters["keep_intersentence_gold"] = True
defaultParameters["no_arg_count_upper_limit"] = False
self.styles = self._setDefaultParameters(defaultParameters)
self.styles = self.getParameters(style)
self.multiEdgeFeatureBuilder = MultiEdgeFeatureBuilder(self.featureSet)
self.multiEdgeFeatureBuilder.noAnnType = self.styles["noAnnType"]
self.multiEdgeFeatureBuilder.maskNamedEntities = not self.styles["noMasking"]
self.multiEdgeFeatureBuilder.maximum = self.styles["maxFeatures"]
#self.tokenFeatureBuilder = TokenFeatureBuilder(self.featureSet)
self.pathLengths = length
assert(self.pathLengths == None)
self.types = types
self.triggerFeatureBuilder = TriggerFeatureBuilder(self.featureSet)
self.triggerFeatureBuilder.useNonNameEntities = True
示例4: __init__
def __init__(self, style=["typed","directed","headsOnly"], length=None, types=[], featureSet=None, classSet=None):
if featureSet == None:
featureSet = IdSet()
if classSet == None:
classSet = IdSet(1)
else:
classSet = classSet
assert( classSet.getId("neg") == 1 )
ExampleBuilder.__init__(self, classSet=classSet, featureSet=featureSet)
self.styles = style
self.multiEdgeFeatureBuilder = MultiEdgeFeatureBuilder(self.featureSet)
if "noAnnType" in self.styles:
self.multiEdgeFeatureBuilder.noAnnType = True
if "noMasking" in self.styles:
self.multiEdgeFeatureBuilder.maskNamedEntities = False
if "maxFeatures" in self.styles:
self.multiEdgeFeatureBuilder.maximum = True
self.tokenFeatureBuilder = TokenFeatureBuilder(self.featureSet)
self.pathLengths = length
assert(self.pathLengths == None)
self.types = types
if "random" in self.styles:
from FeatureBuilders.RandomFeatureBuilder import RandomFeatureBuilder
self.randomFeatureBuilder = RandomFeatureBuilder(self.featureSet)
示例5: devectorizePredictions
def devectorizePredictions(self, predictions):
"""
Converts a dense Numpy array of [examples][width][height][features] into
the corresponding Python list matrices where features are stored in a key-value
dictionary.
"""
targetIds = IdSet(filename=self.model.get(self.tag+"ids.classes"), locked=True)
dimMatrix = int(self.model.getStr("dimMatrix"))
dimLabels = int(self.model.getStr("dimLabels"))
predictions = reshape(predictions, (predictions.shape[0], dimMatrix, dimMatrix, dimLabels))
rangeMatrix = range(dimMatrix)
labels = np.argmax(predictions, axis=-1)
values = np.max(predictions, axis=-1)
minValue = np.min(values)
maxValue = np.max(values)
valRange = maxValue - minValue
print "MINMAX", minValue, maxValue
devectorized = []
for exampleIndex in range(predictions.shape[0]):
#print predictions[exampleIndex]
devectorized.append([])
for i in rangeMatrix:
devectorized[-1].append([])
for j in rangeMatrix:
features = {}
devectorized[-1][-1].append(features)
maxFeature = labels[exampleIndex][i][j]
predValue = predictions[exampleIndex][i][j][maxFeature]
features[targetIds.getName(maxFeature)] = float(predValue)
features["color"] = self.getColor((predValue - minValue) / valRange)
return devectorized
示例6: __init__
def __init__(self, style=["typed", "directed", "headsOnly"], length=None, types=[], featureSet=None, classSet=None):
if featureSet == None:
featureSet = IdSet()
if classSet == None:
classSet = IdSet(1)
else:
classSet = classSet
assert classSet.getId("neg") == 1
ExampleBuilder.__init__(self, classSet=classSet, featureSet=featureSet)
self.styles = style
self.multiEdgeFeatureBuilder = MultiEdgeFeatureBuilder(self.featureSet)
if "noAnnType" in self.styles:
self.multiEdgeFeatureBuilder.noAnnType = True
if "noMasking" in self.styles:
self.multiEdgeFeatureBuilder.maskNamedEntities = False
if "maxFeatures" in self.styles:
self.multiEdgeFeatureBuilder.maximum = True
# self.tokenFeatureBuilder = TokenFeatureBuilder(self.featureSet)
# if "ontology" in self.styles:
# self.multiEdgeFeatureBuilder.ontologyFeatureBuilder = BioInferOntologyFeatureBuilder(self.featureSet)
self.pathLengths = length
assert self.pathLengths == None
self.types = types
示例7: __init__
def __init__(self, style=["typed","directed","headsOnly"], length=None, types=[], featureSet=None, classSet=None, gazetteer=None, pathGazetteer=None, negFrac=None):
if featureSet == None:
featureSet = IdSet()
if classSet == None:
classSet = IdSet(1)
else:
classSet = classSet
assert( classSet.getId("neg") == 1 )
if gazetteer != None:
print >> sys.stderr, "Loading gazetteer from", gazetteer
self.gazetteer=Gazetteer.loadGztr(gazetteer)
else:
print >> sys.stderr, "No gazetteer loaded"
self.gazetteer=None
self.pathGazetteer=None
self.pathGazetteerDependencies = None
self.pathGazetteerPairs = None
if pathGazetteer != None:
print >> sys.stderr, "Loading path gazetteer from", pathGazetteer
self.pathGazetteer=PathGazetteer.load(pathGazetteer)
self.pathGazetteerDependencies = PathGazetteer.getDependencies(self.pathGazetteer)
self.pathGazetteerPairs = PathGazetteer.getPairs(self.pathGazetteer)
else:
print >> sys.stderr, "No path gazetteer loaded"
ExampleBuilder.__init__(self, classSet=classSet, featureSet=featureSet)
self.styles = style
self.negFrac = negFrac
print >> sys.stderr, "Downsampling negatives to", negFrac
self.negRand = random.Random()
self.multiEdgeFeatureBuilder = MultiEdgeFeatureBuilder(self.featureSet)
if True:#"noAnnType" in self.styles:
self.multiEdgeFeatureBuilder.noAnnType = True
if "noMasking" in self.styles:
self.multiEdgeFeatureBuilder.maskNamedEntities = False
if "maxFeatures" in self.styles:
self.multiEdgeFeatureBuilder.maximum = True
self.triggerFeatureBuilder = TriggerFeatureBuilder(self.featureSet)
#self.tokenFeatureBuilder = TokenFeatureBuilder(self.featureSet)
#if "ontology" in self.styles:
# self.multiEdgeFeatureBuilder.ontologyFeatureBuilder = BioInferOntologyFeatureBuilder(self.featureSet)
self.pathLengths = length
assert(self.pathLengths == None)
self.types = types
self.eventsByOrigId = {}
self.headTokensByOrigId = {}
self.interSentenceEvents = set()
self.examplesByEventOrigId = {}
self.skippedByType = {}
self.skippedByTypeAndReason = {}
self.builtByType = {}
self.gazMatchCache = {}
示例8: __init__
def __init__(self, style=None, classSet=None, featureSet=None, gazetteerFileName=None):
if classSet == None:
classSet = IdSet(1)
assert( classSet.getId("neg") == 1 )
if featureSet == None:
featureSet = IdSet()
ExampleBuilder.__init__(self, classSet, featureSet)
self.styles = style
self.triggerFeatureBuilder = TriggerFeatureBuilder(self.featureSet)
self.triggerFeatureBuilder.useNonNameEntities = False
示例9: addExamples
def addExamples(exampleFile, predictionFile, classFile, matrix):
classSet = IdSet(filename=classFile)
f = open(predictionFile, "rt")
for example in ExampleUtils.readExamples(exampleFile, False):
pred = int(f.readline().split()[0])
predClasses = classSet.getName(pred)
goldClasses = classSet.getName(example[1])
for predClass in predClasses.split("---"):
for goldClass in goldClasses.split("---"):
matrix[predClass][goldClass]
matrix[goldClass][predClass] += 1
f.close()
示例10: __init__
def __init__(self, style=None, classSet=None, featureSet=None, gazetteerFileName=None):
if classSet == None:
classSet = IdSet(1)
assert classSet.getId("neg") == 1
if featureSet == None:
featureSet = IdSet()
ExampleBuilder.__init__(self, classSet, featureSet)
self._setDefaultParameters(["co_limits"])
self.styles = self.getParameters(style)
self.triggerFeatureBuilder = TriggerFeatureBuilder(self.featureSet)
self.triggerFeatureBuilder.useNonNameEntities = False
self.phraseTypeCounts = {}
示例11: __init__
def __init__(self, style=["typed","directed"], length=None, types=[], featureSet=None, classSet=None):
if featureSet == None:
featureSet = IdSet()
if classSet == None:
classSet = IdSet(1)
else:
classSet = classSet
assert( classSet.getId("neg") == 1 )
ExampleBuilder.__init__(self, classSet=classSet, featureSet=featureSet)
if style.find(",") != -1:
style = style.split(",")
self.styles = style
self.negFrac = None
self.posPairGaz = POSPairGazetteer()
for s in style:
if s.find("negFrac") != -1:
self.negFrac = float(s.split("_")[-1])
print >> sys.stderr, "Downsampling negatives to", self.negFrac
self.negRand = random.Random(15)
elif s.find("posPairGaz") != -1:
self.posPairGaz = POSPairGazetteer(loadFrom=s.split("_", 1)[-1])
self.multiEdgeFeatureBuilder = MultiEdgeFeatureBuilder(self.featureSet)
self.triggerFeatureBuilder = TriggerFeatureBuilder(self.featureSet)
if "graph_kernel" in self.styles:
from FeatureBuilders.GraphKernelFeatureBuilder import GraphKernelFeatureBuilder
self.graphKernelFeatureBuilder = GraphKernelFeatureBuilder(self.featureSet)
if "noAnnType" in self.styles:
self.multiEdgeFeatureBuilder.noAnnType = True
if "noMasking" in self.styles:
self.multiEdgeFeatureBuilder.maskNamedEntities = False
if "maxFeatures" in self.styles:
self.multiEdgeFeatureBuilder.maximum = True
self.tokenFeatureBuilder = TokenFeatureBuilder(self.featureSet)
if "ontology" in self.styles:
self.multiEdgeFeatureBuilder.ontologyFeatureBuilder = BioInferOntologyFeatureBuilder(self.featureSet)
if "nodalida" in self.styles:
self.nodalidaFeatureBuilder = NodalidaFeatureBuilder(self.featureSet)
#IF LOCAL
if "bioinfer_limits" in self.styles:
self.bioinferOntologies = OntologyUtils.getBioInferTempOntology()
#self.bioinferOntologies = OntologyUtils.loadOntologies(OntologyUtils.g_bioInferFileName)
#ENDIF
self.pathLengths = length
assert(self.pathLengths == None)
self.types = types
if "random" in self.styles:
from FeatureBuilders.RandomFeatureBuilder import RandomFeatureBuilder
self.randomFeatureBuilder = RandomFeatureBuilder(self.featureSet)
示例12: __init__
def __init__(self, style=None, classSet=None, featureSet=None):
if classSet == None:
classSet = IdSet(1)
assert( classSet.getId("neg") == 1 )
if featureSet == None:
featureSet = IdSet()
ExampleBuilder.__init__(self, classSet, featureSet)
self.styles = style
self.timerBuildExamples = Timer(False)
self.timerCrawl = Timer(False)
self.timerCrawlPrecalc = Timer(False)
self.timerMatrix = Timer(False)
self.timerMatrixPrecalc = Timer(False)
示例13: __init__
def __init__(self, style=None, classSet=None, featureSet=None, gazetteerFileName=None):
if classSet == None:
classSet = IdSet(1)
assert( classSet.getId("neg") == 1 )
if featureSet == None:
featureSet = IdSet()
ExampleBuilder.__init__(self, classSet, featureSet)
if gazetteerFileName!=None:
self.gazetteer=Gazetteer.loadGztr(gazetteerFileName)
print >> sys.stderr, "Loaded gazetteer from",gazetteerFileName
else:
print >> sys.stderr, "No gazetteer loaded"
self.gazetteer=None
self.styles = style
示例14: __init__
def __init__(self, style):
ExampleBuilder.__init__(self)
self.featureBuilder = EdgeFeatureBuilder(self.featureSet)
self.style = style
if not "binary" in style:
self.classSet = IdSet(1)
assert( self.classSet.getId("neg") == 1 )
示例15: __init__
def __init__(self, style=None, classSet=None, featureSet=None, gazetteerFileName=None, skiplist=None):
if classSet == None:
classSet = IdSet(1)
assert classSet.getId("neg") == 1
if featureSet == None:
featureSet = IdSet()
ExampleBuilder.__init__(self, classSet, featureSet)
# gazetteerFileName="/usr/share/biotext/GeniaChallenge/SharedTaskTriggerTest/gazetteer-train"
if gazetteerFileName != None:
self.gazetteer = Gazetteer.loadGztr(gazetteerFileName)
print >>sys.stderr, "Loaded gazetteer from", gazetteerFileName
else:
print >>sys.stderr, "No gazetteer loaded"
self.gazetteer = None
self.styles = style
self.skiplist = set()
if skiplist != None:
f = open(skiplist, "rt")
for line in f.readlines():
self.skiplist.add(line.strip())
f.close()
self.styles = [
"trigger_features",
"typed",
"directed",
"no_linear",
"entities",
"genia_limits",
"noMasking",
"maxFeatures",
]
self.multiEdgeFeatureBuilder = MultiEdgeFeatureBuilder(self.featureSet)
if "graph_kernel" in self.styles:
from FeatureBuilders.GraphKernelFeatureBuilder import GraphKernelFeatureBuilder
self.graphKernelFeatureBuilder = GraphKernelFeatureBuilder(self.featureSet)
if "noAnnType" in self.styles:
self.multiEdgeFeatureBuilder.noAnnType = True
if "noMasking" in self.styles:
self.multiEdgeFeatureBuilder.maskNamedEntities = False
if "maxFeatures" in self.styles:
self.multiEdgeFeatureBuilder.maximum = True
self.triggerFeatureBuilder = TriggerFeatureBuilder(self.featureSet)