Changeset 4663:867e68653ee5 in orange


Ignore:
Timestamp:
05/18/08 00:11:07 (6 years ago)
Author:
janezd <janez.demsar@…>
Branch:
default
Convert:
5d3a87358ab9474c42bd5fb86f518ed845c4dbc1
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • orange/doc/reference/userformats.htm

    r2827 r4663  
    1111<index name="defining new file formats"> 
    1212 
    13 <P>You can write your own routines for reading and writing files with examples. This is essentially trivial: a function for loading should get a file name and return <CODE>ExampleTable</CODE> and the function for writing gets the file name and examples and writes the file. No special functionality in Orange is needed for this.</P> 
     13<P>You can write your own routines for reading and writing files with examples. This is essentially trivial: a function for loading should get a file name and a flag named <code>createNewOn</code> telling when to create the new attribute; the latter has to have a default value <code>None</code> and be set to <code>orange.Variable.MakeStatus.NoRecognizedValues</code> in the function itself if <code>None</code> is given. When constructing new attributes, function should do so by calling <code>Variable.make</code>, which accepts the name of the attribute, its type, its values and <code>createNewOn</code>. <code>make</code> will return an attribute and the status of the variable, telling whether a new attribute was created or the old one reused and why. The function should return <CODE>ExampleTable</CODE> and a list of statuses. However, if <code>createNewOn</code> was <code>None</code>, the function should return a plain <code>ExampleTable</code>.</p> 
    1414 
    15 <P>There is one, however. Examples are usually loaded by calling <CODE>ExampleTable</CODE>, giving it a file name as an argument. If the user writes his own routines for a format with file extension, say, ".my", it would be handy if <CODE>ExampleTable</CODE> recognized this extension as well and treated the file format the same way as the built-in formats. And, as you might have guessed, this is possible.</P> 
     15<p>This may not look as trivial as promised, but it is easier explained in Python: see module <code>orngIO.py</code>. There is a function <code>loadArff</code> which you can use as a template.</p> 
    1616 
    17 <P>Here's how you do it. First, define the function(s) for reading and/or writing the examples. You don't need to support both. The function for reading should accept a single argument, the file name, and possibly some keyword arguments; it should return an <CODE>ExampleTable</CODE> with the loaded examples. The writing function gets the file name and the examples, it writes the file(s) and returns nothing.</P> 
     17<p>The function for writing gets the file name and examples and writes the file. No special functionality in Orange is needed for this.</P> 
     18 
     19<P>Examples are usually loaded by calling <CODE>ExampleTable</CODE>, giving it a file name as an argument. If the user writes his own routines for a format with file extension, say, ".my", it would be handy if <CODE>ExampleTable</CODE> recognized this extension as well and treated the file format the same way as the built-in formats. Here's how you do it. First, define the function(s) for reading and/or writing the examples. You don't need to support both. The function for reading should accept a single argument, the file name, and possibly some keyword arguments; it should return an <CODE>ExampleTable</CODE> with the loaded examples. The writing function gets the file name and the examples, it writes the file(s) and returns nothing.</P> 
    1820 
    1921<P>Unless you do it for a strict private use and you really know what you are doing, the reading function should also accept keyword arguments. These should be the same arguments that are usually passed to <CODE>ExampleTable</CODE>, such as <CODE>dontCheckStored</CODE>. You can also add format specific keyword arguments if you will; everything that <CODE>ExampleTable</CODE> is called with gets passed to your function. In addition, and even more important, you should use <A href="domaindepot.htm"><CODE>DomainDepot</CODE>s</A> to construct domains and store them (see documentation on loading <a href="fileformats.htm#samedomain">multiple files with the same domain</a> on why this is needed and the page about <a href="DomainDepot.htm">domain depots</a> to see how it's done).</P> 
Note: See TracChangeset for help on using the changeset viewer.