For example the xsd:string datatype is suite for String data. Which kind of data is suited for the xsd:QName ?
I think a string like xsd:string would be appropriate.
Related
I'm currently parsing out xFrom XML data and displaying it in my app. Sometimes, a question input will have a logical expression attribute that I have to parse and evaluate.
At the simplest level, I’m given a string like this :
"selected(Key,’AnswerToQuestion’)”
Here, I have to parse out the Key, AnswerToQuestion and check my answer dictionary to see if the value of Key is equal to ‘AnswerToQuestion”. This is simple enough.
However in other situations, I am more complex expression such as:
“not(selected(Key,’AnswerToQuestion’) OR selected(Key2,’AnswerToQuestion2’))”
I only need to support "and", "not" and "or" statements.
I am lost on how to tackle this in an efficient way. Something tells me a simple regex won’t cut it and that I’ll need to recursively evaluate it (recursive programming has never been my strong suit). On top of that, I'm given the expression in a string format, which makes things more complicated.
Has anyone done this before? Or can offer some insight?
Thanks
I want to write a generic program to load data from text files or database to a table.
The transformation between the source and destination shouldn't be hard-coded. They may have the format of
ColA = Col1 + Col1 * 1.5
ColB = convert Col3 to date
These rules may need to be converted to SQL or C# code. Does F# already have some library to do these? Is F# the good language to implement it?
With so few specific details in your question, we can't really give you a good answer. But here are a few F# libraries that you might find useful for what you're trying to do:
FSharp.Data - Whether your incoming data is in SQL, CSV, JSON, or XML, there's a type provider that can parse it for you and let you write type-safe queries against it.
FParsec - Lets you easily write custom parsers, so that you can define your transformations in a custom DSL without too much effort. You mentioned custom DSLs in your title, so that's why I'm recommending FParsec. I've used it myself for exactly that purpose, and it was great.
That's about all the help I can give you until I know more details about what you're trying to achieve.
Using Breeze.js for client and BreezeController for the server, the payload sizes that it generates seem inefficient to me. For example when doing a simple paged projection of 3 properties via something like:
.select("Property1, Property2, Property3")
Each record has the following as the type:
"$type":"_IB_eTB9_dNYb7IWzNREO3W5Uer5DOQ8[[System.String, mscorlib],[System.String, mscorlib],[System.String, mscorlib]]
And obviously the more properties I include in my projection the longer this will be, in many cases the type "definition" is significantly longer than the actual data and it is repeated for every row.
Am I worrying over nothing or are there any ways to reduce this?
To answer my own question, I'm going to say I shouldn't worry about this (and it probably applies to more general "metadata over the wire" concerns too)
Assuming we turn on gzip compression, my tests show that all the extraneous metadata makes very little difference to the size of the final compressed payload, which is I guess not surprising.
It's an interesting question. It's really more of an issue when you request projections (queries using the select statement) as opposed to entities because at least for a .NET server, the json serialization of an anonymous type is kind of ugly. Take a look at the results for a query without a select and you'll see that the payload is much more reasonable.
That said, it should be possible for us to modify the default json.net formatter to simplify the serialization of anonymous type information, especially because we basically ignore it on the client anyway once the client realizes that it doesn't match any "known" type. If this interests you please add it to the Breeze User Voice. We do pay attention to these feature requests.
I am curious, is there a faster/better way to parse hashtags in a string, other than using Regular Expressions (mainly in Ruby)?
Edit
For example I want to parse the string This is a #hashtag, and this is #another one! and get the words #hashtag and #another. I am using #\S+ for my regex.
You don't show any code (which you should have) so we're guessing how you are using your regex.
#\S+ is as good of a pattern as you'll need, but scan is probably the best way to retrieve all occurrences in the string.
'This is a #hashtag, and this is #another one!'.scan(/#\S+/)
=> ["#hashtag,", "#another"]
Its should be /\B#\w+/, if you don't want to parse commas
Yes, I agree. /\B#\w+/ makes more sense.
Maybe
Hmm, ideas....
You could try s.split('#'), and then perhaps apply a regex only to actual hashtags
s.split('#').drop(1).map { |x| x[/\w+/] } --- it may or may not be any faster but it clearly is uglier
You could write a C extension that extracts hashtags
You could profile your program and see if it really needs any optimization for this case.
I have implemented a VCARD parser in objective c. Now I want to add support for the MECARD standard. The only difference of a VCARD and a MECARD are the different separators between the fields. Now I'm looking for a good design pattern that helps me to combine both standards into one parser.
Are there any best practices or design patterns for such text parsers?
If your main difference is the separator, abstract it out by creating a parse function that takes your raw input and converts it into an array or some other data structure that does not need separators.