pyparsing

NameError: global name 'dot_parser' is not defined

天大地大妈咪最大 提交于 2019-12-11 01:20:10
问题 I was playing with the decision tree algorithm and trying to plot the tree. However the IDE reported following error: Couldn't import dot_parser, loading of dot files will not be possible. <class 'pandas.core.frame.DataFrame'> Traceback (most recent call last): File "C:/Users/s152730/Desktop/exe1.py", line 70, in <module> graph = pydot.graph_from_dot_data(test.getvalue()) File "C:\Python27\lib\site-packages\pydot.py", line 220, in graph_from_dot_data return dot_parser.parse_dot_data(data)

Build a simple parser that is able to parse different date formats using PyParse

会有一股神秘感。 提交于 2019-12-11 01:04:33
问题 I am building a simple parser that takes a query like the following: 'show fizi commits from 1/1/2010 to 11/2/2006' So far I have: class QueryParser(object): def parser(self, stmnt): keywords = ["select", "from","to", "show","commits", "where", "group by", "order by", "and", "or"] [select, _from, _to, show, commits, where, groupby, orderby, _and, _or] = [ CaselessKeyword(word) for word in keywords ] user = Word(alphas+"."+alphas) user2 = Combine(user + "'s") startdate=self.getdate() enddate

Parser for xml DTD file

谁说胖子不能爱 提交于 2019-12-11 00:36:42
问题 I am quite new in implementing a parser and I am trying to pars a xml DTD file to generate a context free grammar for it. I tried pyparsing and yacc but still I could get any result. So I would appreciate if some one could provide me some tips or sample code to write such a parser. following is a sample DTD file: <!DOCTYPE PcSpecs [ <!ELEMENT PCS (PC*)> <!ELEMENT PC (MODEL, PRICE, PROCESSOR, RAM, DISK+)> <!ELEMENT MODEL (\#PCDATA)> <!ELEMENT PRICE (\#PCDATA)> <!ELEMENT PROCESSOR (MANF, MODEL,

parsing nested structures with pyparsing

我的未来我决定 提交于 2019-12-10 20:46:13
问题 I'm trying to parse a particular syntax for positions in biological sequences. The positions can have forms like: 12 -- a simple position in the sequence 12+34 -- a complex position as a base (12) and offset(+34) 12_56 -- a range, from 12 to 56 12+34_56-78 -- a range as a start to end, where either or both may be simple or complex I'd like to have these parsed as dicts, roughly like this: 12 -> { 'start': { 'base': 12, 'offset': 0 }, 'end': None } 12+34 -> { 'start': { 'base': 12, 'offset':

Partial evaluation with pyparsing

戏子无情 提交于 2019-12-10 18:38:20
问题 I need to be able to take a formula that uses the OpenDocument formula syntax, parse it into syntax that Python can understand, but without evaluating the variables, and then be able to evaluate the formula many times with changing valuables for the variables. Formulas can be user input, so pyparsing allows me to both effectively handle the formula syntax, and clean user input. There are a number of good examples of pyparsing available, but all the mathematical ones seem to assume that one

Not finding the strings expected with pyparsing

▼魔方 西西 提交于 2019-12-10 16:10:26
问题 I'm trying to parse a string using pyparsing. Using the code below import pyparsing as pyp aString = "C((H2)(C(H3))) C((H1)(Cl1)) C(((C(H3))3))" aSub = '(('+ pyp.Word('()'+pyp.srange('[A-Za-z0-9]'))+'))' substituent = aSub('sub') for t,s,e in substituent.scanString(aString): print t.sub I get no output. However, in string aString = "C((H2)(C(H3))) C((H1)(Cl1)) C(((C(H3))3))" there are multiple occurences of ((stuff)) - specifically ((H2)(C(H3))) , C((H1)(Cl1)) and C(((C(H3))3)) . My

How to Separate Output Data

断了今生、忘了曾经 提交于 2019-12-10 12:08:40
问题 Here is my code: #------------------------------------------------------------------------------- # Name: Mocha Rotoscoping Via Blender # Purpose: Make rotoscoping more efficient # # Author: Jeff Owens # # Created: 11/07/2011 # Copyright: (c) jeff.owens 2011 # Licence: Grasshorse #------------------------------------------------------------------------------- #!/usr/bin/env python import sys import os import parser sys.path.append('Z:\_protomotion\Prog\HelperScripts') import GetDir sys.path

pyparsing example

让人想犯罪 __ 提交于 2019-12-09 05:34:42
问题 It is my first attempt to use pyparsing and I'd like to ask how to filter this sample line: survey = '''GPS,PN1,LA52.125133215643,LN21.031048525561,EL116.898812''' to get output like: 1,52.125133215643,21.031048525561,116.898812 In general I have problem with understanding pyparsing logic so any help with this example will be appreciated. Thanks 回答1: You could start with something like this: from pyparsing import * survey = '''GPS,PN1,LA52.125133215643,LN21.031048525561,EL116.898812''' number

python pyparsing “^” vs “|” keywords [closed]

不问归期 提交于 2019-12-08 09:37:00
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 3 years ago . I have a small testcase created to illustrate a problem I am seeing with the "^" operator. When I try and use the ^ operator instead of the | operator below, I get an error. Edit: Just to make the question clearer (although it has already been answered) for anyone else reading it. The question is

How to write grammar for an expression when it can have many possible forms

安稳与你 提交于 2019-12-08 05:17:36
问题 I have some sentences that I need to convert to regex code and I was trying to use Pyparsing for it. The sentences are basically search rules, telling us what to search for. Examples of sentences - LINE_CONTAINS this is a phrase -this is an example search rule telling that the line you are searching on should have the phrase this is a phrase LINE_STARTSWITH However we - this is an example search rule telling that the line you are searching on should start with the phrase However we The rules