Différences

Cette page vous donne les différences entre la révision choisie et la version actuelle de la page.

java:mvcreader [2010/02/16 13:43] (Version actuelle)
suitable créée
Ligne 1: Ligne 1:
 +===== mvcReader =====
 +
 +This class reads data from a properly formatted file and returns a //MultiValuedRelation//, which is a matrix (a vector of vectors) with a name, and row and column labels.
 +
 +
 + public class MvcReader
 +   extends AbstractReader
 +   implements MultiValuedRelationReader {
 +
 +   public MvcReader(Reader r) {
 +           super(r);
 +   }
 + 
 +   public MultiValuedRelation readMultiValuedRelation() throws BadInputDataException,IOException {
 +
 +  - verify the file is properly identified :      if(!getStream().readLine().trim().equals("[Multi-Valued Relation]")) throw new IOException("The MVC file does not start with : [Multi-Valued Relation]\n");
 +  - initialize properties 
 +    - MultiValuedRelation mvRel=null;
 +    - String nomRel=getStream().readLine().trim();
 +    - StringTokenizer sk=null;
 +    - sk=new StringTokenizer(getStream().readLine().trim(),"|"); ** columns are separated by "|", first data line contains the object names (I guess) **
 +    - Vector lesObjs=new Vector();
 +    - add each identifier from the tokenized stream as an object
 +      -  while(sk.hasMoreElements() ){ lesObjs.add(new DefaultFormalObject(sk.nextElement().toString() ) ); }
 +    - now do the same for the attribute names :
 +      * sk=new StringTokenizer(getStream().readLine().trim(),"|");
 +      * Vector lesAtts=new Vector();
 +      * while(sk.hasMoreElements() ){ lesAtts.add(new DefaultFormalAttribute(sk.nextElement().toString() ) ); }
 +    - build the MultiValuedRelation with the rest of the data
 +      * mvRel=new MultiValuedRelation(lesObjs.size(),lesAtts.size() );
 +      * mvRel.setRelationName(nomRel);
 +      * for(int i=0;i<lesObjs.size();i++) { mvRel.replaceObject(i,(FormalObject)lesObjs.elementAt(i) ); }
 +      * for(int j=0;j<lesAtts.size();j++) { mvRel.replaceAttribute(j,(FormalAttribute)lesAtts.elementAt(j) ); }
 +      * StringTokenizer st2;
 +      * String val;
 +      * for(int i=0;i<lesObjs.size();i++) { ((check the line is useable : sk=new StringTokenizer(getStream().readLine().trim(),"|"); if(sk==null || sk.countTokens()<lesAtts.size() ) { throw new BadInputDataException("Some relationships are missing in the MVC file.\n"); } ))
 +        * int j=0;
 +        * while(sk.hasMoreElements()) { String vTmp=sk.nextToken().trim();  st2=new StringTokenizer(vTmp,"@");
 +          * while(st2.hasMoreElements() ){ val=st2.nextToken().trim(); if(!val.equals("0")){                              mvRel.addValuedRelation((FormalObject)lesObjs.elementAt(i),(FormalAttribute)lesAtts.elementAt(j),new FormalAttributeValue(val) ); }
 +          *   }
 +        *   j++;
 +      *  }
 +    -  return mvRel;  }
 +
 +==== imports ====
 +  package lattice.io;
 +   
 +  import java.io.IOException;
 +  import java.io.Reader;
 +  import java.util.StringTokenizer;
 +  import java.util.Vector;
 +  
 +  import lattice.util.concept.DefaultFormalAttribute;
 +  import lattice.util.concept.DefaultFormalObject;
 +  import lattice.util.concept.FormalAttribute;
 +  import lattice.util.concept.FormalAttributeValue;
 +  import lattice.util.concept.FormalObject;
 +  import lattice.util.exception.BadInputDataException;
 +  import lattice.util.relation.MultiValuedRelation;
  
 
java/mvcreader.txt · Dernière modification: 2010/02/16 13:43 par suitable
 
Sauf mention contraire, le contenu de ce wiki est placé sous la licence suivante :CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki