Comments (12)
I just pushed a commit which added a getNames() method to Scope. So you could do something like:
Scope s = Scope.create();
Parser.parse("a*b+c", s);
s.getName(); // Will contain all referenced variables
Note that I didn't update the maven release yet, but that wouldn't be a problem if required...
from parsii.
Cool just what I wanted, can you update the Maven repo, cause it just happens I'm using Maven, and would not want to add it to my nexus repo.
from parsii.
Also for convienance I think it would be conveniant for the Expr to have a function returning the scope, for places where the expression parsing and evaluation is done in different classes. Now you would need to store both expr and scope, and recall both at usage time.
from parsii.
Technically the scope is only used when parsing expressions. That's the place where variable names are resolved into Variable instances. Accessing a variable later on is as cheap as a field access - no more lookups are performed. This is one reason for parsii being quite fast. If you still need / want those two tied together, you could create class "Computation" or the like with two fields "expression" and "scope". That should probably do the trick?
I just released parsii-1.2 (should take about one day to be mirrored into the main repo).
from parsii.
I see. So for the following use case: let there be a user provided arbitrary expression, such as "a+b" (but may as well be x+y).
To make the calculation my initial impluse is:
s = Scope.create()
expr = Expr.parse(stringExpresion, s);
much later on, in different class, expr and scope passed as reference:
names=s.getNames()
for i=1:100000
for name in names:
s.getVariable(name).setValue(get(i, name))
res[i] = expr.evaluate()
Let us assume that get always returns some value. If I understand correctly what you say is that evaluate always returns the expression with the scope variables at parse time? (meaning that I would need to reparse the expression again and again) Am I right?
Furthermore, I could of course write myself an enclosing class, but I have its place would be right inside the parsii.
from parsii.
Almost - you don't need to reparse the expression and expr doesn't have a setVariable method. The code would roughly look like this:
names=s.getNames()
for i=1:10
for name:names:
Variable v = s.find(name);
v.setValue(get(i, name));
res[i] = expr.evaluate();
We could make this way more performant by providing a Scope.getVariables() method which directly returns all known variables:
for i = 1..10:
for v : s.getVariables():
v.setValue(get(i, v.getName()));
res[i] = expr.evaluate();
This way, no lookups are performed in the inner loop. Would that work for you?
from parsii.
That would be excelent. :)
from parsii.
I just added such a method - A snapshot is available as: parsii-1.3-20140514.161553-1.jar or 1.3-SNAPSHOT should also resolve to this revision. This might also take some hour to be mirrored...
from parsii.
So I'like now how it works, but is it neccessary to return pi and euler as these are constants?
I mean for now I would not to write an if to escape them... and all my code would certainly break if later on we introduce another constant. But the extra ifs alone would make akward to use it. Maybe we should add a getNonConstantVariableNames() function where to escape these? Any ideas for these?
from parsii.
I added a getter: getLocalVariables - this will exclude all global constants (as those would reside in the global root context). A maven snapshot is available...
Another sexy approach would have been using java 8: scope.getVariables().stream().filter(v -> !v.isConstant()).forEach(.....) ;-)
from parsii.
I cannot see the snapshot mirrored (http://mvnrepository.com/artifact/com.scireum/parsii), any ideas why?
from parsii.
As far as I'm aware of, you need to add the snapshot repository of sonatype
to your list of repos:
https://oss.sonatype.org/content/repositories/snapshots (Sorry I'm by no
means a maven expert).
freundliche Grüße
scireum GmbH
Andreas Haufler
Geschäftsführer
scireum GmbH, Alfred-Klingele-Str. 6, 73630 Remshalden
Unser Service - gerne für Sie da:
Vertrieb: (07151) 20637 10
Support: (07151) 20637 20 - E-Mail: [email protected]
Tel.: (07151) 20637 21 - E-Mail: [email protected]
Fax: (07151) 20637 19 - Internet: http://www.scireum.de
Geschäftsführer: Michael Haufler, Andreas Haufler
Amtsgericht Stuttgart, HRB 732171
2014-05-22 10:19 GMT+02:00 Gábor Bernát [email protected]:
I cannot see the snapshot mirrored (
http://mvnrepository.com/artifact/com.scireum/parsii), any ideas why?—
Reply to this email directly or view it on GitHubhttps://github.com//issues/2#issuecomment-43860292
.
from parsii.
Related Issues (20)
- Parsing Block Comments HOT 1
- Add support for parentheses with positive sign HOT 1
- Trailing decimal point and signed number after operand HOT 2
- Feature request: Add support for series variables HOT 1
- Handle unknown variables HOT 4
- Cross compile option not working? HOT 2
- How to calculate use BigDecimal? HOT 1
- Exponent issue HOT 6
- Evaluating expression with context HOT 1
- Performance Optimizations and additional Features in invesdwin-util fork
- need jar
- Latest is not on maven central
- Is there a way to get a max value? HOT 4
- logical-not operation supported?
- Scientific notation HOT 3
- Is this thread safe? HOT 1
- can i use it to get derivative formula,or integral calculus,how can i do?
- JDK 1.6 runtime issue: UnsupportedClassVersionError HOT 3
- Parser Error HOT 2
- Floating-point literals starting with decimal point HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from parsii.