Skip to content
Snippets Groups Projects
Commit ff245095 authored by jezozwierzak's avatar jezozwierzak
Browse files

Merge branch 'master' of nlp.pwr.wroc.pl:corpus2

parents d55d81ca 2086ac32
Branches
No related merge requests found
...@@ -19,9 +19,11 @@ or FITNESS FOR A PARTICULAR PURPOSE. ...@@ -19,9 +19,11 @@ or FITNESS FOR A PARTICULAR PURPOSE.
#include <libcorpus2/exception.h> #include <libcorpus2/exception.h>
#include <libcorpus2_whole/io/relwriter.h> #include <libcorpus2_whole/io/relwriter.h>
#include <fstream> #include <iostream>
#include <sstream> #include <sstream>
#include <fstream>
#include <boost/make_shared.hpp> #include <boost/make_shared.hpp>
using namespace std;
namespace Corpus2 { namespace Corpus2 {
namespace whole { namespace whole {
...@@ -33,73 +35,38 @@ RelationWriter::RelationWriter(const std::string &rela_path) ...@@ -33,73 +35,38 @@ RelationWriter::RelationWriter(const std::string &rela_path)
void RelationWriter::write(const std::vector< boost::shared_ptr<Relation> >& relations) void RelationWriter::write(const std::vector< boost::shared_ptr<Relation> >& relations)
{ {
file_.reset(new std::ofstream(rela_path_.c_str())); ofstream ofs(rela_path_.c_str(), ofstream::out);
//header //header
file_->write("<relations>\n",12); ofs<<"<relations>\n";
//relations
foreach (const boost::shared_ptr<Relation>& r, relations){ foreach (const boost::shared_ptr<Relation>& r, relations){
file_->write(" <rel name=\"",14); ofs<<" <rel name=\"";
std::streamsize size = r->name().size(); ofs<<r->name().c_str()<<"\">"<<endl;
file_->write(r->name().c_str(),size); ofs<<" <from sent=\"";
//Maybe additional info about set is needed in Relation class ofs<<r->from()->sentence_id();
//file_->write("\" set=\"Anaphora\">\n",18); ofs<<"\" chan=\"";
file_->write("\">\n",3); ofs<<r->from()->channel_name();
file_->write(" <from sent=\"",18); ofs<<"\">";
size = r->from()->sentence_id().size(); ofs<<r->from()->annotation_number();
file_->write(r->from()->sentence_id().c_str(),size); ofs<<"</from>"<<endl;
file_->write("\" chan=\"",8); ofs<<" <to sent=\"";
size = r->from()->channel_name().size(); ofs<<r->to()->sentence_id();
file_->write(r->from()->channel_name().c_str(),size); ofs<<"\" chan=\"";
file_->write("\">",2); ofs<<r->to()->channel_name();
int an_num = r->from()->annotation_number(); ofs<<"\">";
std::ostringstream ss; ofs<<r->to()->annotation_number();
ss << an_num; ofs<<"</to>"<<endl;
std::string str = ss.str(); ofs<<" </rel>"<<endl;
size=str.size();
file_->write(str.c_str(),size);
file_->write("</from>\n",8);
file_->write(" <to sent=\"",16);
size = r->to()->sentence_id().size();
file_->write(r->to()->sentence_id().c_str(),size);
file_->write("\" chan=\"",8);
size = r->to()->channel_name().size();
file_->write(r->to()->channel_name().c_str(),size);
file_->write("\">",2);
an_num = r->to()->annotation_number();
std::ostringstream ss1;
ss1 << an_num;
str = ss1.str();
size=str.size();
file_->write(str.c_str(),size);
file_->write("</to>\n",6);
//file_->write("\n",1);
file_->write(" </rel>",9);
file_->write("\n",1);
} }
//footer //footer
file_->write("</relations>",12); ofs<<"</relations>";
file_->close(); ofs.close();
} }
void write_relation(const boost::shared_ptr<Relation>& r)
{
//std::streamsize size = r->from()->sentence_id().size();
//f->write(r->from()->sentence_id().c_str(),size);
}
void do_header(){
}
void do_footer(){
}
} // whole ns } // whole ns
} // Corpus2 ns } // Corpus2 ns
......
...@@ -24,8 +24,6 @@ or FITNESS FOR A PARTICULAR PURPOSE. ...@@ -24,8 +24,6 @@ or FITNESS FOR A PARTICULAR PURPOSE.
#include <libcorpus2_whole/relation.h> #include <libcorpus2_whole/relation.h>
#include <libcorpus2/io/xmlwriter.h>
#include <iostream> #include <iostream>
namespace Corpus2 { namespace Corpus2 {
...@@ -33,8 +31,7 @@ namespace whole { ...@@ -33,8 +31,7 @@ namespace whole {
/** /**
* A reader for realtion documents. Note that document is read into memory * A writer for realtion documents.
* before any processing may take place.
*/ */
class RelationWriter { class RelationWriter {
public: public:
...@@ -44,6 +41,7 @@ public: ...@@ -44,6 +41,7 @@ public:
*/ */
RelationWriter(const std::string &rela_path); RelationWriter(const std::string &rela_path);
/** /**
* Lazy relations accessor. * Lazy relations accessor.
* If relations are not readed then read relations and returns list of them. * If relations are not readed then read relations and returns list of them.
...@@ -54,29 +52,10 @@ public: ...@@ -54,29 +52,10 @@ public:
private: private:
void write_relation(const boost::shared_ptr<Relation>& r);
void do_header();
void do_footer();
// -------------------------------------------------------------------------
/// List of the relations in given relation file
std::vector< boost::shared_ptr<Relation> > relations_;
/// Path to file with relations /// Path to file with relations
std::string rela_path_; std::string rela_path_;
/// File pointer
boost::shared_ptr<std::ofstream> file_;
// -------------------------------------------------------------------------
// Temporary information of actual parsing relation
std::string rel_name_;
std::string ann_number_;
boost::shared_ptr<DirectionPoint> rel_from_;
boost::shared_ptr<DirectionPoint> rel_to_;
}; };
} // whole ns } // whole ns
......
...@@ -9,14 +9,11 @@ ...@@ -9,14 +9,11 @@
namespace Corpus2 { namespace Corpus2 {
namespace whole { namespace whole {
class RelationWriter { class RelationWriter {
public: public:
RelationWriter(const std::string &rela_path); RelationWriter(const std::string &rela_path);
void write(const std::vector< boost::shared_ptr<Relation> > relations); void write(const std::vector< boost::shared_ptr<Relation> > relations);
private:
void do_header();
void do_footer();
//void write_relation(const boost::shared_ptr<Relation>& r);
}; };
} // whole ns } // whole ns
} // Corpus2 ns } // Corpus2 ns
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment