|
| 1 | +// -*- C++ -*- |
| 2 | + |
| 3 | +// VMatDictionaryCommand.cc |
| 4 | +// |
| 5 | +// Copyright (C) 2006 Pascal Vincent |
| 6 | +// |
| 7 | +// Redistribution and use in source and binary forms, with or without |
| 8 | +// modification, are permitted provided that the following conditions are met: |
| 9 | +// |
| 10 | +// 1. Redistributions of source code must retain the above copyright |
| 11 | +// notice, this list of conditions and the following disclaimer. |
| 12 | +// |
| 13 | +// 2. Redistributions in binary form must reproduce the above copyright |
| 14 | +// notice, this list of conditions and the following disclaimer in the |
| 15 | +// documentation and/or other materials provided with the distribution. |
| 16 | +// |
| 17 | +// 3. The name of the authors may not be used to endorse or promote |
| 18 | +// products derived from this software without specific prior written |
| 19 | +// permission. |
| 20 | +// |
| 21 | +// THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR |
| 22 | +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 23 | +// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN |
| 24 | +// NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED |
| 26 | +// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 27 | +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 28 | +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 29 | +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 30 | +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | +// |
| 32 | +// This file is part of the PLearn library. For more information on the PLearn |
| 33 | +// library, go to the PLearn Web site at www.plearn.org |
| 34 | + |
| 35 | +// Authors: Pascal Vincent |
| 36 | + |
| 37 | +/*! \file VMatDictionaryCommand.cc */ |
| 38 | + |
| 39 | + |
| 40 | +#include "VMatDictionaryCommand.h" |
| 41 | +#include <plearn/vmat/DictionaryVMatrix.h> |
| 42 | +#include <plearn/db/getDataSet.h> |
| 43 | +#include <plearn/io/load_and_save.h> |
| 44 | + |
| 45 | +namespace PLearn { |
| 46 | +using namespace std; |
| 47 | + |
| 48 | +//! This allows to register the 'VMatDictionaryCommand' command in the command registry |
| 49 | +PLearnCommandRegistry VMatDictionaryCommand::reg_(new VMatDictionaryCommand); |
| 50 | + |
| 51 | +VMatDictionaryCommand::VMatDictionaryCommand() |
| 52 | + : PLearnCommand( |
| 53 | + "vmat_dictionary", |
| 54 | + "Create Dictionary objects for each field of a vmat", |
| 55 | + "Will create <dataset>.field#.dict, where # is the\n" |
| 56 | + "field (column) number, starting at 0. Those files contain the plearn\n" |
| 57 | + "scripts of the Dictionary objets for each field.\n" |
| 58 | + ) |
| 59 | +{} |
| 60 | + |
| 61 | +//! The actual implementation of the 'VMatDictionaryCommand' command |
| 62 | +void VMatDictionaryCommand::run(const vector<string>& args) |
| 63 | +{ |
| 64 | + PPath indexf= ""; |
| 65 | + string vmat_file = args[0]; |
| 66 | + string ext = extract_extension(vmat_file); |
| 67 | + VMat vmat; |
| 68 | + if(ext == ".txt") |
| 69 | + { |
| 70 | + DictionaryVMatrix* dvmat = new DictionaryVMatrix(); |
| 71 | + TVec<PPath> file_names(1); |
| 72 | + file_names[0] = vmat_file; |
| 73 | + dvmat->file_names = file_names; |
| 74 | + dvmat->delimiters = ""; |
| 75 | + dvmat->build(); |
| 76 | + vmat = dvmat; |
| 77 | + } |
| 78 | + else |
| 79 | + vmat = getDataSet(vmat_file); |
| 80 | + |
| 81 | + for(int i=0; i<vmat->width(); i++) |
| 82 | + { |
| 83 | + if(vmat->getDictionary(i)) |
| 84 | + { |
| 85 | + string dico_name = vmat_file + ".col" + tostring(i) + ".dict"; |
| 86 | + save(dico_name,*(vmat->getDictionary(i))); |
| 87 | + } |
| 88 | + } |
| 89 | +} |
| 90 | + |
| 91 | +} // end of namespace PLearn |
| 92 | + |
| 93 | + |
| 94 | +/* |
| 95 | + Local Variables: |
| 96 | + mode:c++ |
| 97 | + c-basic-offset:4 |
| 98 | + c-file-style:"stroustrup" |
| 99 | + c-file-offsets:((innamespace . 0)(inline-open . 0)) |
| 100 | + indent-tabs-mode:nil |
| 101 | + fill-column:79 |
| 102 | + End: |
| 103 | +*/ |
| 104 | +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 : |
0 commit comments