Skip to content
Snippets Groups Projects
Select Git revision
  • 33dc14dab2adf5efd9d72c34fd00cb0006af1fe3
  • master default protected
  • develop protected
  • feat_remove_attr
  • python2.7
  • python3.8
6 results

chunk.cpp

Blame
  • user avatar
    ilor authored
    initial switch to use shared_ptrs for sentence and chunk objects, ale get rid of the pointless sentence template
    e548853b
    History
    chunk.cpp 1.46 KiB
    /*
        Copyright (C) 2010 Tomasz Śniatowski, Adam Radziszewski
        Part of the libcorpus2 project
    
        This program is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by the Free
    Software Foundation; either version 3 of the License, or (at your option)
    any later version.
    
        This program is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    or FITNESS FOR A PARTICULAR PURPOSE. 
    
        See the LICENSE and COPYING files for more details.
    */
    
    #include <libcorpus2/chunk.h>
    #include <libpwrutils/foreach.h>
    #include <boost/make_shared.hpp>
    
    namespace Corpus2 {
    
    Chunk::Chunk()
    {
    }
    
    Chunk::~Chunk()
    {
    }
    
    boost::shared_ptr<Chunk> Chunk::clone_shared() const
    {
    	boost::shared_ptr<Chunk> copy = boost::make_shared<Chunk>();
    	foreach (const boost::shared_ptr<Sentence>& s, sentences_) {
    		copy->append(s->clone_shared());
    	}
    	copy->attributes_ = attributes_;
    	return copy;
    }
    
    bool Chunk::has_attribute(const std::string &name) const
    {
    	return attributes_.find(name) != attributes_.end();
    }
    
    std::string Chunk::get_attribute(const std::string &name) const
    {
    	std::map<std::string, std::string>::const_iterator i;
    	i = attributes_.find(name);
    	if (i != attributes_.end()) {
    		return i->second;
    	} else {
    		return "";
    	}
    }
    
    void Chunk::set_attribute(const std::string &name,
    		const std::string &value)
    {
    	attributes_[name] = value;
    }
    
    } /* end ns Corpus2 */