I have a number of partial views that deal with different derived classes of Foo.
Each derived class has a number of properties exclusive to that class.
The properties in the base class , Foo, all contain data annotations, such as Required, Range, etc. Unfortunately these don't seem to be triggering when I have a strongly typed view using a derived class.
It simply allows me to post the form with incorrect data. What is the best strategy for dealing with this?
I've defined a few types in a common.xsd I have multiple XSDs which have types that extend from the same type in common. When I generate the classes the #XmlSeeAlso attribute keeps getting updated to the most recent xsd being used.
Is it possible to tell the compiler that when the common class is generated there are more than one classes which can extend from it ?
I have been successfully using UIMA ConceptMapper with a dictionary that I built. I set the TokenAnnotation parameter to uima.tt.TokenAnnotation and the SpanFeatureStructure parameter to uima.tt.SentenceAnnotation (based on the reference example). These types are I believe coming from the OpenNLP parser. But I also do another parse using medkatp and would like to use their types. So far I have not figured out how to do that. If I change either of these two parameters the whole thing fails saying that it cannot find the type.
I've searched for hours on the net but have found no examples of ConceptMapper that use anything except these two types. Any suggestions are welcome.
These types are I believe coming from the OpenNLP parser.
These types are defined in the component descriptor (usually, in the desc folder), under the tag <typeSystemDescription>
But I also do another parse using medkatp and would like to use their types.
If you want to use other types (from other UIMA components, or your own types), you need to define them wherever you use them (meaning: in every component descriptor where you need it, under the tag <typeSystemDescription>).
What is the best way to represent a byte array as an XSD schema? I have a byte input which I need to parse and to feed to Java objects generated by JAXB out of an XSD schema for future validation. Every piece of information in my input is defined by offset and the length. I would like to attach this information to my elements so I could then read it from generated classes and use for parsing. The only way to attach such additional information to an Element I can think of is representing every Element as a Complex Type and then adding attributes to the complex Element and restrictions – to the simple Element wrapped by this complex Element. The problem with this approach (in addition to the Schema looking messy) is that JAXB will create separate class for every Element (Complex Type). And I will have a lot of fields in my input. :) The second issue is that I will in fact attach attributes and restrictions (which I need for validation) to different elements (wrapped simple element and the complex wrapper). So I will need to find a way to figure out that they in fact represent the same piece of information. I hope all this make sense. :) Basically my question is: can you think of a more elegant way to attach position and length information to an XSD element that represents the corresponding piece of a byte array? Thanks!
What is the best way to represent a
byte array as an XSD schema? I have a
byte input which I need to parse and
to feed to Java objects generated by
JAXB out of an XSD schema for future
validation.
JAXB will convert a byte[] to/from elements and attributes of type xsd:base64Binary.
For information on starting from XML schema see:
http://bdoughan.blogspot.com/2011/05/schema-to-java-xmlmimetype.html
For information on starting from Java classes see:
http://bdoughan.blogspot.com/2011/03/jaxb-web-services-and-binary-data.html
One of the huge benefits in languages that have some sort of reflection/introspecition is that objects can be automatically constructed from a variety of sources.
For example, in Java I can use the same objects for persisting to a db (with Hibernate), serializing to XML (with JAXB), and serializing to JSON (json-lib). You can do the same in Ruby and Python also usually following some simple rules for properties or annotations for Java.
Thus I don't need lots "Domain Transfer Objects". I can concentrate on the domain I am working in.
It seems in very strict FP like Haskell and Ocaml this is not possible.
Particularly Haskell. The only thing I have seen is doing some sort of preprocessing or meta-programming (ocaml). Is it just accepted that you have to do all the transformations from the bottom upwards?
In other words you have to do lots of boring work to turn a data type in haskell into a JSON/XML/DB Row object and back again into a data object.
I can't speak to OCaml, but I'd say that the main difficulty in Haskell is that deserialization requires knowing the type in advance--there's no universal way to mechanically deserialize from a format, figure out what the resulting value is, and go from there, as is possible in languages with unsound or dynamic type systems.
Setting aside the type issue, there are various approaches to serializing data in Haskell:
The built-in type classes Read/Show (de)serialize algebraic data types and most built-in types as strings. Well-behaved instances should generally be such that read . show is equivalent to id, and that the result of show can be parsed as Haskell source code constructing the serialized value.
Various serialization packages can be found on Hackage; typically these require that the type to be serialized be an instance of some type class, with the package providing instances for most built-in types. Sometimes they merely require an automatically derivable instance of the type-reifying, reflective metaprogramming Data class (the charming fully qualified name for which is Data.Data.Data), or provide Template Haskell code to auto-generate instances.
For truly unusual serialization formats--or to create your own package like the previously mentioned ones--one can reach for the biggest hammer available, sort of a "big brother" to Read and Show: parsing and pretty-printing. Numerous packages are available for both, and while it may sound intimidating at first, parsing and pretty-printing are in fact amazingly painless in Haskell.
A glance at Hackage indicates that serialization packages already exist for various formats, including binary data, JSON, YAML, and XML, though I've not used any of them so I can't personally attest to how well they work. Here's a non-exhaustive list to get you started:
binary: Performance-oriented serialization to lazy ByteStrings
cereal: Similar to binary, but a slightly different interface and uses strict ByteStrings
genericserialize: Serialization via built-in metaprogramming, output format is extensible, includes R5RS sexp output.
json: Lightweight serialization of JSON data
RJson: Serialization to JSON via built-in metaprogramming
hexpat-pickle: Combinators for serialization to XML, using the "hexpat" package
regular-xmlpickler: Serialization to XML of recursive data structures using the "regular" package
The only other problem is that, inevitably, not all types will be serializable--if nothing else, I suspect you're going to have a hard time serializing polymorphic types, existential types, and functions.
For what it's worth, I think the pre-processor solution found in OCaml (as exemplified by sexplib, binprot and json-wheel among others) is pretty great (and I think people do very similar things with Template Haskell). It's far more efficient than reflection, and can also be tuned to individual types in a natural way. If you don't like the auto-generated serializer for a given type foo, you can always just write your own, and it fits beautifully into the auto-generated serializers for types that include foo as a component.
The only downside is that you need to learn camlp4 to write one of these for yourself. But using them is quite easy, once you get your build-system set up to use the preprocessor. It's as simple as adding with sexp to the end of a type definition:
type t = { foo: int; bar: float }
with sexp
and now you have your serializer.
You wanted
to do lot of boring work to turn a data type in haskell into JSON/XML/DB Row object and back again into a data object.
There are many ways to serialize and unserialize data types in Haskell. You can use for example,
Data.Binary
Text.JSON
as well as other common formants (protocol buffers, thrift, xml)
Each package often/usually comes with a macro or deriving mechanism to allow you to e.g. derive JSON. For Data.Binary for example, see this previous answer: Erlang's term_to_binary in Haskell?
The general answer is: we have many great packages for serialization in Haskell, and we tend to use the existing class 'deriving' infrastructure (with either generics or template Haskell macros to do the actual deriving).
My understanding is that the simplest way to serialize and deserialize in Haskell is to derive from Read and Show. This is simple and isn't fullfilling your requirements.
However there are HXT and Text.JSON which seem to provide what you need.
The usual approach is to employ Data.Binary. This provides the basic serialisation capability. Binary instances for data types are easy to write and can easily be built out of smaller units.
If you want to generate the instances automatically then you can use Template Haskell. I don't know of any package to do this, but I wouldn't be surprised if one already exists.