Hi all
I've written a python program that adds orders into our order routing
simulation system. It works well, and has a syntax along these lines:
./neworder --instrument NOKIA --size 23 --price MARKET --repeats 20
etc
However, I'd like to add a mode that will handle, say:
./neworder buy 23 NOKIA at MKT x 20
I could enter several orders either by running multiple times, or use a
comma-separated approach, like:
./neworder buy 23 NOKIA at MKT on helsinki, sell 20 NOKIA at market on
helsinki
The thing about this is that its a "tolerant" parser, so all of these
should also work:
# omit words like "at", "on"
./neworder buy 23 NOKIA mkt helsinki
# take any symbol for helsinki
./neworder buy 23 mkt helsinki
# figure out that market=helsinki
./neworder buy 23 NOKIA at market price
I've started writing a simple state-based parser, usage like:
class NaturalLanguage InsructionBuild er:
def parse( self, arglist ):
"""Given a sequence of args, return an Instruction object"""
...
return Instruction( instrument, size, price, ... )
class Instruction:
"""encapsul ate a single instruction to buy, sell, etc"""
def __init__( self, instrument, size, price, ... ):
...
This doesn't work yet, but I know with time I'll get there.
Question is - is there a module out there that will already handle this
approach?
Thanks for any suggestions :)
Andrew 4 2179
> Question is - is there a module out there that will already handle this approach?
Try the python nltk. I haven't done stuff with it so far, but I'd certainly
give it a try when I need natural language support. http://nltk.sourceforge.net/
--
Regards,
Diez B. Roggisch
Le Sun, 17 Apr 2005 13:38:09 +0200, Andrew E a écrit : Hi all
I've written a python program that adds orders into our order routing simulation system. It works well, and has a syntax along these lines:
./neworder --instrument NOKIA --size 23 --price MARKET --repeats 20
etc
However, I'd like to add a mode that will handle, say:
./neworder buy 23 NOKIA at MKT x 20
I could enter several orders either by running multiple times, or use a comma-separated approach, like:
./neworder buy 23 NOKIA at MKT on helsinki, sell 20 NOKIA at market on helsinki
It would be simpler to have the rule : one line == one order, action,
command wahtever. The thing about this is that its a "tolerant" parser, so all of these should also work:
# omit words like "at", "on" ./neworder buy 23 NOKIA mkt helsinki
# take any symbol for helsinki ./neworder buy 23 mkt helsinki
# figure out that market=helsinki ./neworder buy 23 NOKIA at market price
You have some variation of the same « buy » order. If you want to detail
the semantics : you arrive to determine the different parameter of a
BuyCommand : what, where, how (many) ...
This semantic is expressed differently in english, US-english, french
...
If you base your parser on regex you see that the same BuyOrder is
represented by a number of variant :
Please, buy 23 NOKIA at market Helsinki
Acheter 40 actions Bouygues à la Bouse de Paris
So you have for a given environment (orders management module) a number
of commands expressed in pseudo-natural languages. Each command has a
certain number of attributes
name, module_name, parameters, variants(list of regexps for instance),
description, short description, sample sentence (to be presented
to the user in an interactive session if requested).
An important attribute is naturally the action taken when the
parser/interpreter matches the current line.
So you group the description of the Commands in an easy to parse file
and write an interpreter which on startup read such a file for the
Commands it understands : command to load a module, to list the commands
in the currently loaded module or in the interpreter, command to display
the sample, short or long description (help about cmd or how to spell
cmd)., command to stop the interpreter (and the program) ...
command to read/include a file containings commands to parse and
execute.
Python is dynamic, with setattr() you can easily construct a Command
object from its description.
Here is what could be the description of a command to compute the
equilibrium position in a stability module (using a «here» shell like
syntax ):
command equilibre << eoc
description << eod
La commande « equilibre » permet de lancer le calcul de la position
d'équilibre du flotteur couramment décrit.
position equilibre en partant de pqr 0.0/0.0/1.0 et h=8.500
les mots-clés sont equilibre pqr et h[=]
eod
sample <<eos
equilibre pqr 0.0/0.0/1.0 avec h=8.500
eos
# name of function to call
action compute_equi
# parameters of the command (a dictionary of parameters could be in
# action's arguments
parameters << eop
pqr
h
eop
# The regexpes
variants << eov
# the following regexp is with re.I (ignore case flag) :
variant I << eovi
equilibrer?\spq r\s+(?P<pqr>\d* \.\d*/\d*\.\d*/\d*\.\d*)\s+(?P <h>\d*\.\d*)
eovvi
# syntax of regexp untested :-)
variant << eovi
equilibrium\spq r\s+(?P<pqr>\d* \.\d*/\d*\.\d*/\d*\.\d*)\s+(?P <h>\d*\.\d*)
eovvi
eov
eoc
Thanks for any suggestions :)
Andrew
"Andrew E" <an****@nospam. com> wrote in message
news:d3******** **@news.hispeed .ch... Hi all
I've written a python program that adds orders into our order routing simulation system. It works well, and has a syntax along these lines:
./neworder --instrument NOKIA --size 23 --price MARKET --repeats 20
etc
However, I'd like to add a mode that will handle, say:
./neworder buy 23 NOKIA at MKT x 20
I could enter several orders either by running multiple times, or use a comma-separated approach, like:
./neworder buy 23 NOKIA at MKT on helsinki, sell 20 NOKIA at market on helsinki
The thing about this is that its a "tolerant" parser, so all of these should also work:
# omit words like "at", "on" ./neworder buy 23 NOKIA mkt helsinki
# take any symbol for helsinki ./neworder buy 23 mkt helsinki
# figure out that market=helsinki ./neworder buy 23 NOKIA at market price
I've started writing a simple state-based parser, usage like:
class NaturalLanguage InsructionBuild er:
def parse( self, arglist ): """Given a sequence of args, return an Instruction object""" ... return Instruction( instrument, size, price, ... )
class Instruction: """encapsul ate a single instruction to buy, sell, etc"""
def __init__( self, instrument, size, price, ... ): ...
This doesn't work yet, but I know with time I'll get there.
Question is - is there a module out there that will already handle this approach?
Thanks for any suggestions :)
There's NLTK (on Sourceforge) which has already been mentioned.
However, it's a teaching tool, not a real production natural language
parser.
I'd suggest you step back from the problem and take a wider
view. Parsing natural language, in all its variations, is an unsolved
research problem that is part of what has given Artificial Intelligence
somewhat of a black eye.
Your problem is, however, much simpler than the general one:
you've got a limited number of commands which pretty much
all follow the VO (verb operands) pattern.
You've also got a lot of words from limited and disjunct
vocabularies that can be used to drive the parse. In your example,
at least one of 'buy' and 'sell' is required to start a clause,
MKT is one of maybe a half dozen
qualifiers that specify other information that must be present,
there are a limited number of exchanges, and the number of
shares seems to be the only number present.
I'd also take a bit of advice from the XP community: don't
write the library first, wait until you've got at least three
working examples so you know the services that the
library really needs to support.
John Roth Andrew
Andrew E wrote: Hi all
I've written a python program that adds orders into our order routing simulation system. It works well, and has a syntax along these lines:
./neworder --instrument NOKIA --size 23 --price MARKET --repeats 20
etc
However, I'd like to add a mode that will handle, say:
./neworder buy 23 NOKIA at MKT x 20
I could enter several orders either by running multiple times, or use
a comma-separated approach, like:
./neworder buy 23 NOKIA at MKT on helsinki, sell 20 NOKIA at market
on helsinki
You could add a string option instead:
$ neworder -c 'buy 23 NOKIA at MKT on helsinki, sell 20 NOKIA at market
on helsinki'
This would leave your current option parsing in tact. Then just
split on the comma.
Another suggestion would be to drop into an interactive mode if
no arguments are passed:
$ neworder
->? buy 23 NOKIA at MKT on helsinki
->? sell 20 NOKIA at market on helsinki
->? ^d
The thing about this is that its a "tolerant" parser, so all of these should also work:
# omit words like "at", "on" ./neworder buy 23 NOKIA mkt helsinki
# take any symbol for helsinki ./neworder buy 23 mkt helsinki
# figure out that market=helsinki ./neworder buy 23 NOKIA at market price
I've started writing a simple state-based parser, usage like:
class NaturalLanguage InsructionBuild er:
def parse( self, arglist ): """Given a sequence of args, return an Instruction object""" ... return Instruction( instrument, size, price, ... )
class Instruction: """encapsul ate a single instruction to buy, sell, etc"""
def __init__( self, instrument, size, price, ... ): ...
This doesn't work yet, but I know with time I'll get there.
Question is - is there a module out there that will already handle
this approach?
Thanks for any suggestions :)
Andrew
If I were in your situation, I'd probably write a BNF for the
tiny-language. This would help wrap my brain around the problem.
The BNF would help show what kind of regular expression you are
looking at creating as well.
--
bytecolor This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Zhang Weiwu |
last post by:
Hello. I am working with a php software project, in it
(www.egroupware.org) Chinese simplified locate is "zh" while Traditional
Chinese "tw".
I wish to send correct language attribute in http header, I found "zh"
is not standard. I found this line in apache2's default httpd.conf
# Simplified Chinese (zh-CN)
AddLanguage zh-CN .zh-cn
|
by: anon |
last post by:
Dear Microsoft:
In your new ASP.NET 2.0 page model of being able to crosspost to another
page, it would seem that if you were to type that word in Google,
"crosspost" or "cross post", you will get endless amount of results from the
newsgroup police complaining about posters cross posting to many newsgroups
as this very message is doing.
So to those at Microsoft, and since posting your form results to another
page is very very...
|
by: Lars Erik Thorsplass |
last post by:
I have recently ventured into the exciting world of stored procedures,
but I have now become lost.
Background:
Am currently working on access control in a web application. My goal
is to process access control on the SQL level. This way if a row is in
the result set, you have access to it, if not, you dont.
|
by: Paul McGuire |
last post by:
I just published my first article on ONLamp, a beginner's walkthrough for
pyparsing.
Please check it out at
http://www.onlamp.com/pub/a/python/2006/01/26/pyparsing.html, and be sure to
post any questions or comments.
-- Paul
|
by: Andrew Gwozdziewycz |
last post by:
I've been looking recently for date processing modules that can parse
dates in forms such as
"next week" or "6 days from next sunday". PHP has a function that
will do this called 'strtotime',
but I have not found a Python implementation. I've check the standard
date, datetime and time
modules and also mx.Date* modules. Am I overlooking something here or
does it not exist?
Anyone know of an implementation? Also, I realize that this is...
| |
by: jonnyblazed |
last post by:
I've searched everywhere for this but I'm not sure exactly what to
search for.
What I am trying to do is pass a variable to a php script via the URL.
However, I don't want to use the standard "?name=value format." I want
to either pass the variable as "value website.com" or
"website.com/value" where the script is stored in some directory
"website.com/script/index.php" and the value gets stored in a variable
declared within my php script.
|
by: Shelly |
last post by:
I am coding a psudo-cron job into an application that I am writing. I don't
have access to write a real cron job.
Here is what I did:
1 - I downloaded pseudocron.php from its website
(www.bitfolge.de/pseudocron)
2 - I created a cronjob directory and put a crontab.txt in there and had the
pseudocron.php hook up with it by properly configuring the section in that
script.
3 - I put an require_once("pseudocron.php") in my login screen so...
|
by: Daniel Fetchinson |
last post by:
Many times a more user friendly date format is convenient than the
pure date and time.
For example for a date that is yesterday I would like to see
"yesterday" instead of the date itself. And for a date that was 2 days
ago I would like to see "2 days ago" but for something that was 4 days
ago I would like to see the actual date. This is often seen in web
applications, I'm sure you all know what I'm talking about.
I'm guessing this...
|
by: k3pp0 |
last post by:
Hey.
I've got a very basic newbie question, I hope you can understand me.
Sorry for asking it, first of all.
I see a lot of sites (e.g. communities) with a url-structure like
this: example.com/users/paul (displaying the user profile of "paul")
or example.com/pictures/landscapes/13 (displaying pictures from the
category "landscapes", page 13). These are just examples, I hope I
didn't confuse you.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |