本文整理汇总了Python中inphosite.model.meta.Session.query方法的典型用法代码示例。如果您正苦于以下问题:Python Session.query方法的具体用法?Python Session.query怎么用?Python Session.query使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类inphosite.model.meta.Session
的用法示例。
在下文中一共展示了Session.query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: evaluate
# 需要导入模块: from inphosite.model.meta import Session [as 别名]
# 或者: from inphosite.model.meta.Session import query [as 别名]
def evaluate(self, id=None):
if not h.auth.is_logged_in():
abort(401)
c.idea = h.fetch_obj(Idea, id, new_id=True)
node_q = Session.query(Node).filter_by(concept_id=id)
c.node = node_q.first()
if request.environ.get('REMOTE_USER', False):
user = h.get_user(request.environ['REMOTE_USER'])
sq = Session.query(IdeaEvaluation.cons_id)
sq = sq.filter(IdeaEvaluation.ante==c.idea)
sq = sq.filter(IdeaEvaluation.uid==user.ID)
sq = sq.subquery()
to_evaluate = c.idea.related.outerjoin((sq, Idea.ID==sq.c.cons_id))
to_evaluate = to_evaluate.filter(sq.c.cons_id==None)
else:
to_evaluate = c.idea.related
c.paginator = paginate.Page(
to_evaluate,
page=int(request.params.get('page', 1)),
items_per_page=10,
controller='idea',
action='edit',
id=id
)
return render('idea/idea-edit.html')
示例2: graph_all
# 需要导入模块: from inphosite.model.meta import Session [as 别名]
# 或者: from inphosite.model.meta.Session import query [as 别名]
def graph_all(self, filetype='html', limit=False):
sep_filter = request.params.get('sep_filter', False)
c.sep_filter = sep_filter
idea_q = Session.query(Idea)
c.ideas = idea_q.all()
edge_q =\
Session.query(IdeaGraphEdge).order_by(IdeaGraphEdge.jweight.desc()).limit(3*len(c.ideas))
c.edges = edge_q.all()
return render('idea/graph_all.' + filetype)
示例3: addlist
# 需要导入模块: from inphosite.model.meta import Session [as 别名]
# 或者: from inphosite.model.meta.Session import query [as 别名]
def addlist():
#simply returns the list of published or about to be published sepentries that do not yet have sep_dir fields in the entity table
entities_q = Session.query(Entity)
entities_q = entities_q.filter(Entity.sep_dir != None)
entities_q = entities_q.subquery()
missing = Session.query(SEPEntry)
missing = missing.outerjoin((entities_q, SEPEntry.sep_dir == entities_q.c.sep_dir))
missing = missing.filter(entities_q.c.sep_dir == None)
#suppress snark, sample
missing = missing.filter(SEPEntry.title != "Snark")
missing = missing.filter(SEPEntry.title != "Sample")
missing = missing.filter(or_(SEPEntry.published == 1, SEPEntry.status == 'au_submit_proofread'))
return missing.all()
示例4: complete_mining
# 需要导入模块: from inphosite.model.meta import Session [as 别名]
# 或者: from inphosite.model.meta.Session import query [as 别名]
def complete_mining(entity_type=Idea, filename='graph.txt', root='./'):
occur_filename = root + "graph-" + filename
edge_filename = root + "edge-" + filename
sql_filename = root + "sql-" + filename
print "processing articles..."
process_articles(entity_type, occur_filename)
print "running apriori miner..."
dm.apriori(occur_filename, edge_filename)
print "processing edges..."
edges = dm.process_edges(occur_filename, edge_filename)
ents = dm.calculate_node_entropy(edges)
edges = dm.calculate_edge_weight(edges, ents)
print "creating sql files..."
with open(sql_filename, 'w') as f:
for edge, props in edges.iteritems():
ante,cons = edge
row = "%s::%s" % edge
row += "::%(confidence)s::%(jweight)s::%(weight)s\n" % props
f.write(row)
print "updating term entropy..."
for term_id, entropy in ents.iteritems():
term = Session.query(Idea).get(term_id)
if term:
term.entropy = entropy
Session.flush()
Session.commit()
示例5: list
# 需要导入模块: from inphosite.model.meta import Session [as 别名]
# 或者: from inphosite.model.meta.Session import query [as 别名]
def list(self, filetype='html', redirect=False):
thinker_q = Session.query(Thinker)
c.query = ''
c.sep = ''
if request.params.get('sep_filter'):
idea_q = idea_q.filter(Idea.sep_dir != '')
if filetype=='json':
response.content_type = 'application/json'
# check for query
if request.params.get('q'):
c.query = request.params['q']
thinker_q = thinker_q.filter(Thinker.name.like(u'%'+request.params['q']+'%'))
# if only 1 result, go ahead and view that thinker
if redirect and thinker_q.count() == 1:
return self.view(thinker_q.first().ID, filetype)
if request.params.get('sep'):
thinker_q = thinker_q.filter(Thinker.sep_dir == request.params['sep'])
c.sep = request.params['sep']
# if only 1 result, go ahead and view that thinker
if redirect and thinker_q.count() == 1:
return self.view(thinker_q.first().ID, filetype)
c.thinkers = thinker_q.all()
return render('thinker/thinker-list.' + filetype)
示例6: fuzzymatch
# 需要导入模块: from inphosite.model.meta import Session [as 别名]
# 或者: from inphosite.model.meta.Session import query [as 别名]
def fuzzymatch(string1):
#note: fuzzymatch.php must be in php path, e.g. /usr/lib/php/!!!
#put in a cron job that runs every half hour for new entries?
entities = Session.query(Entity)
matches = []
##string1 = string1.decode('utf8')
for entity in entities:
php = PHP("require 'fuzzymatch.php';")
#php = PHP()
#print "testing " + entity.label.encode('utf8') + " against " + string1.encode('utf8') + "\n"
code = '$string1 = utf8_decode("' + string1.encode('utf8') + '");'
#code = code + "$string2 = '" + entity.label.encode('latin-1', 'replace') + "';"
#code = code + "print $string1; print $string2;"
#print code + '$string2 = utf8_decode("' + entity.label.encode('utf8') + '");'
code = code + '$string2 = utf8_decode("' + entity.label.encode('utf8') + '");'
code = code + """print fuzzy_match($string1, $string2, 2);"""
verdict = php.get_raw(code)
#print "verdict is " + verdict + "\n"
if float(verdict)>=.5:
#print entity.label + " is a match!\n"
entity.matchvalue = verdict
matches.append(entity)
return matches
示例7: list
# 需要导入模块: from inphosite.model.meta import Session [as 别名]
# 或者: from inphosite.model.meta.Session import query [as 别名]
def list(self, filetype="html", redirect=False):
node_q = Session.query(Node)
# check for query
if request.params.get("q"):
node_q = node_q.filter(Node.name.like(u"%" + request.params["q"] + "%"))
# if only 1 result, go ahead and view that node
if redirect and node_q.count() == 1:
h.redirect(h.url(controller="taxonomy", action="view", id=node_q.first().ID, filetype=filetype))
if filetype == "html":
c.nodes = Session.query(Node).filter(Node.parent_id == None).order_by("name").all()
return render("taxonomy/node-list.html")
else:
c.nodes = node_q.all()
return render("taxonomy/node-list.%s" % filetype)
示例8: admin
# 需要导入模块: from inphosite.model.meta import Session [as 别名]
# 或者: from inphosite.model.meta.Session import query [as 别名]
def admin(self, id=None):
if not h.auth.is_logged_in():
abort(401)
if not h.auth.is_admin():
abort(403)
c.sepdirnew = False
c.alreadysepdir = False
redirect = request.params.get('redirect', False)
add = request.params.get('add', False)
limit = request.params.get('limit', None)
entity_q = Session.query(Entity)
c.found = False
c.custom = False
c.new = False
if request.params.get('q'):
q = request.params['q']
o = Entity.label.like(q)
entity_q = entity_q.filter(o).order_by(func.length(Entity.label))
# if only 1 result, go ahead and view that idea
if redirect and entity_q.count() == 1:
print "have a q, entityq count = 1"
c.journal = h.fetch_obj(Journal, entity_q.first().ID)
c.found = True
id = c.journal.ID
c.message = 'Entity edit page for journal ' + c.journal.name
if request.params.get('entry_sep_dir'):
entry_sep_dir = request.params['entry_sep_dir']
if not (c.journal.sep_dir):
c.journal.sep_dir = request.params['entry_sep_dir']
c.sepdirnew = True
else:
c.alreadysepdir = True
c.entry_sep_dir = request.params['entry_sep_dir']
return render('admin/journal-edit.html')
else:
print "That didn't journal."
if id is None:
print "I am here"
c.message = "Please input an entity label using the search bar to the left."
return render ('admin/idea-edit.html')
else:
c.journal = h.fetch_obj(Journal, id)
c.found = True
c.message = 'Entity edit page for journal ' + c.journal.name
if request.params.get('entry_sep_dir'):
entry_sep_dir = request.params['entry_sep_dir']
if not (c.journal.sep_dir):
c.journal.sep_dir = request.params['entry_sep_dir']
c.sepdirnew = True
else:
c.alreadysepdir = True
c.entry_sep_dir = request.params['entry_sep_dir']
return render ('admin/journal-edit.html')
示例9: list
# 需要导入模块: from inphosite.model.meta import Session [as 别名]
# 或者: from inphosite.model.meta.Session import query [as 别名]
def list(self, filetype='html'):
redirect = request.params.get('redirect', False)
limit = request.params.get('limit', None)
idea_q = Session.query(Idea)
c.query = ''
c.sep = ''
#c.nodes = Session.query(Node).filter(Node.parent_id == None).order_by("name").all()
if request.params.get('sep_filter'):
idea_q = idea_q.filter(Idea.sep_dir != '')
# Check for query
if request.params.get('q'):
q = request.params['q']
c.query = q
o = or_(Idea.label.like(q+'%'), Idea.label.like('% '+q+'%'))
idea_q = idea_q.filter(o).order_by(Idea.entropy.desc())
# if only 1 result, go ahead and view that idea
if redirect and idea_q.count() == 1:
h.redirect(h.url(controller='idea', action='view', id=idea_q.first().ID,filetype=filetype))
else:
c.ideas = idea_q.limit(limit)
return render('idea/idea-list.' + filetype)
#TODO: Error handling - we shouldn't have multiple results
if request.params.get('sep'):
idea_q = idea_q.filter(Idea.sep_dir == request.params['sep'])
c.sep = request.params['sep']
# if only 1 result, go ahead and view that idea
if redirect and idea_q.count() == 1:
h.redirect(h.url(controller='idea', action='view', id=idea_q.first().ID,filetype=filetype))
elif idea_q.count() == 0:
h.redirect(h.url(controller='entity', action='list', filetype=filetype, sep=request.params['sep'], redirect=redirect))
else:
c.ideas = idea_q.limit(limit)
return render('idea/idea-list.' + filetype)
all_param = request.params.get('all', False)
node_param = request.params.get('nodes', True)
instance_param = request.params.get('instances', True)
node_q = idea_q.join((Node,Node.concept_id==Idea.ID))
instance_q = idea_q.join(Instance.idea)
if all_param:
idea_q = idea_q
if not node_param:
idea_q = idea_q.except_(node_q)
if not instance_param:
idea_q = idea_q.except_(instance_q)
elif node_param:
idea_q = node_q
if instance_param:
idea_q = idea_q.union(instance_q)
elif instance_param:
idea_q = instance_q
c.ideas = idea_q.limit(limit)
return render('idea/idea-list.' + filetype)
示例10: get_subgraph
# 需要导入模块: from inphosite.model.meta import Session [as 别名]
# 或者: from inphosite.model.meta.Session import query [as 别名]
def get_subgraph(ids, thresh=None):
edge_q = Session.query(IdeaGraphEdge)
edge_q = edge_q.order_by(IdeaGraphEdge.jweight.desc())
edge_q = edge_q.filter(IdeaGraphEdge.cons_id.in_(ids))
edge_q = edge_q.filter(IdeaGraphEdge.ante_id.in_(ids))
if thresh:
edge_q = edge_q.filter(IdeaGraphEdge.jweight > thresh)
return edge_q.all()
示例11: get_user
# 需要导入模块: from inphosite.model.meta import Session [as 别名]
# 或者: from inphosite.model.meta.Session import query [as 别名]
def get_user(login):
"""
Returns the User object from the model.
:rtype: :class:`inphosite.model.User`
"""
user = Session.query(User).filter(or_(User.email==login,
User.username==login.lower())).first()
return user
示例12: list
# 需要导入模块: from inphosite.model.meta import Session [as 别名]
# 或者: from inphosite.model.meta.Session import query [as 别名]
def list(self, filetype='html', redirect=False):
journal_q = Session.query(Journal)
# check for query
if request.params.get('q'):
journal_q = journal_q.filter(Journal.name.like(u'%'+request.params['q']+'%'))
# if only 1 result, go ahead and view that journal
if redirect and journal_q.count() == 1:
return self.view(journal_q.first().id, filetype)
c.journals = list(journal_q)
return render('journal/journal-list.' + filetype)
示例13: _get_anon_evaluation
# 需要导入模块: from inphosite.model.meta import Session [as 别名]
# 或者: from inphosite.model.meta.Session import query [as 别名]
def _get_anon_evaluation(self, id, id2, ip, autoCreate=True):
idea1 = h.fetch_obj(Idea, id, new_id=True)
idea2 = h.fetch_obj(Idea, id2, new_id=True)
evaluation_q = Session.query(AnonIdeaEvaluation)
evaluation = evaluation_q.filter_by(ante_id=id, cons_id=id2, ip=ip).first()
# if an evaluation does not yet exist, create one
if autoCreate and not evaluation:
evaluation = AnonIdeaEvaluation(id, id2,ip)
Session.add(evaluation)
return evaluation
示例14: _list_property
# 需要导入模块: from inphosite.model.meta import Session [as 别名]
# 或者: from inphosite.model.meta.Session import query [as 别名]
def _list_property(self, property, id, filetype='html', limit=False, sep_filter=False, type='idea'):
c.idea = h.fetch_obj(Idea, id)
limit = request.params.get('limit', limit)
sep_filter = request.params.get('sep_filter', sep_filter)
property = getattr(c.idea, property)
if sep_filter:
property = property.filter(Entity.sep_dir != '')
if limit:
property = property[0:limit-1]
c.ideas = property
c.nodes = Session.query(Node).filter(Node.parent_id == None).order_by("name").all()
return render('%s/%s-list.%s' %(type, type, filetype))
示例15: process_articles
# 需要导入模块: from inphosite.model.meta import Session [as 别名]
# 或者: from inphosite.model.meta.Session import query [as 别名]
def process_articles(entity_type=Idea, filename='output.txt'):
# process entities
ideas = Session.query(entity_type)
# do not process Nodes or Journals
ideas = ideas.filter(and_(Entity.typeID!=2, Entity.typeID!=4))
ideas = ideas.all()
articles = Session.query(entity_type).filter(entity_type.sep_dir!='').all()
corpus_root = config['app_conf']['corpus']
with open(filename, 'w') as f:
for article in articles:
filename = article.get_filename(corpus_root)
if filename and os.path.isfile(filename):
print "processing:", article.sep_dir
try:
doc = extract_article_body(filename)
lines = dm.prepare_apriori_input(doc, ideas, article)
f.writelines(lines)
except:
print "ERROR PROCESSING:", article.sep_dir
else:
print "BAD SEP_DIR:", article.sep_dir