mwDocumentRestrictionLevel CWord2007DocumentImpl::GetRestrictionLevel()
{
	LOG_WS_FUNCTION_SCOPE();
	try
	{
		WordBinaryDocumentTagger tagger(m_sWorkingFileName);

		mwDocumentRestrictionLevel eRestrictionLevel = NO_RESTRICTION;
		if (tagger.IsInternalOnly())
			eRestrictionLevel = EXTERNAL_RESTRICTION;
		else if (tagger.IsFullyRestricted())
			eRestrictionLevel = FULL_RESTRICTION;

		return eRestrictionLevel;
	}
	catch(const Workshare::Exception&)
	{
	}
	catch(...)
	{
		unexpected();
	}

	IDispatchPtr pDoc = NULL;

	try
	{
		pDoc = InstanceManager->OpenDocument(m_sWorkingFileName.c_str(), VARIANT_TRUE);

		WordDOMDocumentTagger tagger(pDoc);

		mwDocumentRestrictionLevel eRestrictionLevel = NO_RESTRICTION;
		if (tagger.IsInternalOnly())
			eRestrictionLevel = EXTERNAL_RESTRICTION;
		else if (tagger.IsFullyRestricted())
			eRestrictionLevel = FULL_RESTRICTION;

		InstanceManager->CloseDocument(pDoc, false);
		return eRestrictionLevel;
	}
	catch(const Workshare::Exception&)
	{
		InstanceManager->CloseDocument(pDoc, false);
		throw;
	}
	catch(...)
	{
		InstanceManager->CloseDocument(pDoc, false);
		unexpected();
	}
}
bool CWord2007DocumentImpl::IsRestrictionPasswordValid(const CStdString& password)
{  
	LOG_WS_FUNCTION_SCOPE();
   IDispatchPtr spDocument = InstanceManager->OpenDocument(m_sWorkingFileName.c_str(), VARIANT_FALSE);
   try
   {
		WordDOMDocumentTagger tagger(spDocument);
		if(!tagger.IsInternalOnly() && !tagger.IsFullyRestricted())
         throw Workshare::Com::ComException(_T("This document is not restricted, checking for restriction password is not valid."), E_FAIL);

		CStdString sExistingPassword = tagger.GetPassword();

      CStdString sEncryptedPassword;
      if(!password.IsEmpty())
         sEncryptedPassword = EncryptText(password);  

      InstanceManager->CloseDocument(spDocument, true);

      return (sEncryptedPassword.Equals(sExistingPassword));
   }
   catch(const Workshare::Exception&)
   {
      InstanceManager->CloseDocument(spDocument, true);
      throw;
   }
   catch(...)
   {
      InstanceManager->CloseDocument(spDocument, true);
      unexpected();
   }
}
bool CWord2007DocumentImpl::IsPasswordProtected()
{
	LOG_WS_FUNCTION_SCOPE();
   IDispatchPtr pDoc = InstanceManager->OpenDocument(m_sWorkingFileName.c_str(), VARIANT_FALSE);
   try
   {
		WordDOMDocumentTagger tagger(pDoc);

		CStdString sExistingPassword = tagger.GetPassword();

      bool bPasswordProtected = !sExistingPassword.IsEmpty();

      InstanceManager->CloseDocument(pDoc, false);

      return bPasswordProtected;
   }
   catch(const Workshare::Exception&)
   {
      InstanceManager->CloseDocument(pDoc, true);
      throw;
   }
   catch(...)
   {
      InstanceManager->CloseDocument(pDoc, true);
      unexpected();
   }
}
Example #4
0
CStdString GetClassification(IDispatchPtr spOfficeDoc)
{
   LOG_WS_FUNCTION_SCOPE();

   WordDOMDocumentTagger tagger(spOfficeDoc);
	
   return tagger.GetClassification();
}
void CWord2007DocumentImpl::SetRestrictionLevel(const mwDocumentRestrictionLevel eRestrictionLevel, const CStdString* sPassword /*= NULL*/)
{
	LOG_WS_FUNCTION_SCOPE();
   if (eRestrictionLevel < NO_RESTRICTION)
      throw Workshare::ArgumentException(_T("eRestrictionLevel"), _T("The restriction level, which is less than NO_RESTRICTION, is invalid. The value must be NO_RESTRICTION(0), EXTERNAL_RESTRICTION(1) or FULL_RESTRICTION(2)."));

   if (eRestrictionLevel > FULL_RESTRICTION)
      throw Workshare::ArgumentException(_T("eRestrictionLevel"), _T("The restriction level, which is greater than FULL_RESTRICTION, is invalid. The value must be NO_RESTRICTION(0), EXTERNAL_RESTRICTION(1) or FULL_RESTRICTION(2)."));

   CStdString sEncryptedPassword;
   if(sPassword)
      if(!sPassword->IsEmpty())
         sEncryptedPassword = EncryptText(*sPassword);

   IDispatchPtr pDoc = InstanceManager->OpenDocument(m_sWorkingFileName.c_str(), VARIANT_FALSE);

   try
   {
		WordDOMDocumentTagger tagger(pDoc);

		CStdString sExistingPassword = tagger.GetPassword();

      if(!sExistingPassword.IsEmpty() && !sEncryptedPassword.Equals(sExistingPassword) && !sEncryptedPassword.empty())
      {
         SetLastError(ERROR_INVALID_DATA);
         throw Workshare::System::SystemException(_T("Invalid password"));
      }

	  tagger.ClearRestrictions();

      if (EXTERNAL_RESTRICTION == eRestrictionLevel)
      {
		  tagger.SetInternalOnly(true);
		  tagger.SetPassword(sEncryptedPassword);
      }
      else if(FULL_RESTRICTION == eRestrictionLevel)
      {
         tagger.SetFullRestriction(true);
         tagger.SetPassword(sEncryptedPassword);
      }
	  else
	  {
         tagger.SetPassword(sEncryptedPassword);
	  }

      InstanceManager->CloseDocument(pDoc, true);
   }
   catch(const Workshare::Exception&)
   {
      InstanceManager->CloseDocument(pDoc, true);
      throw;
   }
   catch(...)
   {
      InstanceManager->CloseDocument(pDoc, true);
      unexpected();
   }
}
Example #6
0
CStdString GetRestrictionLevel(IDispatchPtr spOfficeDoc)
{
   LOG_WS_FUNCTION_SCOPE();

   WordDOMDocumentTagger tagger(spOfficeDoc);
   if (tagger.IsInternalOnly())
		return c_sInternalOnly;

	if(tagger.IsFullyRestricted())
		return c_sFullRestriction;

	return c_sNoRestriction;
}
Example #7
0
void Train(const std::string& dataset, const std::string& model) {
    NGramMaker ngram;
    LabelSet ls;
    Document doc = Parse(dataset, ngram, ls);

    SequenceTaggerParams tagger(ngram.dict().size(), ls.size());

    std::cout << tagger.Train(doc) << "% accuracy FINAL" << std::endl;

    std::ofstream out(model);
    out << ngram.Serialize();
    out << ls.Serialize();
    out << tagger.Serialize();

    InteractiveShell(tagger, ngram, ls);
}
void TestPDFDocumentTagger::TestWithReadProtected()
{
	bool canOpen = false;
	CStdString fileName = CreateTestResultDocument(TEST_FILE_READ_PROTECTED, _T(__FUNCTION__));
	try
	{
		PDFDocumentTagger tagger(fileName);
		canOpen = true;
		assertMessage(!tagger.IsFullyRestricted(), _T("An adobe generated document thats read protected cannot be restricted"));
		assertThrows(tagger.SetFullyRestricted(), Workshare::PasswordProtectedDocumentException);
		assertThrows(tagger.SetInternalOnly(), Workshare::PasswordProtectedDocumentException);
	}
	catch(const Workshare::FileFormatVersionNotSupportedException&)
	{
	}
	assertMessage(!canOpen, _T("Expected a failure while opening a read (password) protected pdf document."));
}
Example #9
0
void Tagging(const string &strModelPrefix, 
						 const string &strIn, 
						 const string &strOut)
{
	CRBMNN rbmNN;
	CNNScorer nnScorer(&rbmNN);
	CWordTagManager lexicon;
	CTemplateManager tempMgr;
	CBaseExtractor *pExtor = NULL;
	CTagger tagger(false, false);
	
	string strPrefix = strModelPrefix;
	if (strPrefix.back() == '.')
		strPrefix.erase(strPrefix.begin() + strPrefix.size() - 1);
	
	Load(strPrefix, nnScorer, tempMgr, &pExtor);
	tagger.Init(pExtor, &lexicon, &nnScorer, CConfig::nBS);
	CPool pool;
	
	vector<_SEN *> senVecGold = CReader::ReadSentences(strIn, pool);
	vector<_SEN *> senVec = _SEN::CopySentences(senVecGold, pool);
	
	fprintf(stderr, "Total %d sentences\n", (int)senVec.size());
	Tagging(senVec, tagger);	
	
	FILE *fpOut = fopen(strOut.c_str(), "w");
	assert(fpOut != NULL);
	for (size_t i = 0; i < senVec.size(); ++i)
	{
		_SEN *pRes = senVec[i];
		for (int k = 0; k < pRes->Length(); ++k)
			fprintf(fpOut, "%-15s %-15s %s\n",	wstr2utf8(pRes->Word(k)).c_str(), 
							wstr2utf8(pRes->GForm(k)).c_str(),
							pRes->GForm(k) == wstring(L"url") ? "ADD" : wstr2utf8(pRes->Tag(k)).c_str());
		fprintf(fpOut, "\n");
	}

	fclose(fpOut);
	SEvalRecorder eRec = EvalSentences(senVec, senVecGold, "");
	fprintf(stderr, "Total %d, correct %d, accuracy %.2f%%\n", 
			eRec.nTotal,  eRec.nCorrect,  100.0 * eRec.nCorrect/eRec.nTotal);
	delete tagger.GetExtractor();
}
Example #10
0
bool BrowseTableModel::setData(const QModelIndex &index, const QVariant &value,
                               int role) {
    Q_UNUSED(role);

    if (!index.isValid()) {
        return false;
    }
    qDebug() << "BrowseTableModel::setData(" << index.data() << ")";
    int row = index.row();
    int col = index.column();
    QString track_location = getTrackLocation(index);
    AudioTagger tagger(track_location);

    // set tagger information
    tagger.setArtist(this->index(row, COLUMN_ARTIST).data().toString());
    tagger.setTitle(this->index(row, COLUMN_TITLE).data().toString());
    tagger.setAlbum(this->index(row, COLUMN_ALBUM).data().toString());
    tagger.setKey(this->index(row, COLUMN_KEY).data().toString());
    tagger.setBpm(this->index(row, COLUMN_BPM).data().toString());
    tagger.setComment(this->index(row, COLUMN_COMMENT).data().toString());
    tagger.setTracknumber(
        this->index(row, COLUMN_TRACK_NUMBER).data().toString());
    tagger.setYear(this->index(row, COLUMN_YEAR).data().toString());
    tagger.setGenre(this->index(row, COLUMN_GENRE).data().toString());
    tagger.setComposer(this->index(row, COLUMN_COMPOSER).data().toString());

    // check if one the item were edited
    if (col == COLUMN_ARTIST) {
        tagger.setArtist(value.toString());
    } else if (col == COLUMN_TITLE) {
        tagger.setTitle(value.toString());
    } else if (col == COLUMN_ALBUM) {
        tagger.setAlbum(value.toString());
    } else if (col == COLUMN_BPM) {
        tagger.setBpm(value.toString());
    } else if (col == COLUMN_KEY) {
        tagger.setKey(value.toString());
    } else if (col == COLUMN_TRACK_NUMBER) {
        tagger.setTracknumber(value.toString());
    } else if (col == COLUMN_COMMENT) {
        tagger.setComment(value.toString());
    } else if (col == COLUMN_GENRE) {
        tagger.setGenre(value.toString());
    } else if (col == COLUMN_COMPOSER) {
        tagger.setComposer(value.toString());
    } else if (col == COLUMN_YEAR) {
        tagger.setYear(value.toString());
    }


    QStandardItem* item = itemFromIndex(index);
    if (tagger.save()) {
        // Modify underlying interalPointer object
        item->setText(value.toString());
        item->setToolTip(item->text());
        return true;
    } else {
        // reset to old value in error
        item->setText(index.data().toString());
        item->setToolTip(item->text());
        QMessageBox::critical(
            0, tr("Mixxx Library"),
            tr("Could not update file metadata.")
            + "\n" +track_location);
        return false;
    }
}
Example #11
0
int mecab_do(int argc, char **argv) {

    //debug
    std::cout << "[" << __LINE__ << "]: "
              << "mecab_do(int argc, char **argv)" << __FILE__ << std::endl;
    ///

#define WHAT_ERROR(msg) do {                    \
    std::cout << msg << std::endl;              \
    return EXIT_FAILURE; }                      \
  while (0);

//	//debug
//	std::cout << "[" << __LINE__ << "]: " << __FILE__ << std::endl;
//	WHAT_ERROR("ABCDE");
//	///

    MeCab::Param param;
    if (!param.open(argc, argv, MeCab::long_options)) {
        std::cout << param.what() << std::endl;
        return EXIT_FAILURE;
    }

    if (param.get<bool>("help")) {
        std::cout << param.help() << std::endl;
        return EXIT_SUCCESS;
    }

    if (param.get<bool>("version")) {
        std::cout << param.version() << std::endl;
        return EXIT_SUCCESS;
    }

    if (!load_dictionary_resource(&param)) {
        std::cout << param.what() << std::endl;
        return EXIT_SUCCESS;
    }

    if (param.get<int>("lattice-level") >= 1) {
        std::cerr << "lattice-level is DEPERCATED. "
                  << "use --marginal or --nbest." << std::endl;
    }

    //debug
    std::cout << "[" << __LINE__ << "]: " << __FILE__ << std::endl;
    int dbg = param.get<int>("lattice-level");

    std::cout << "	param.get<int>(\"lattice-level\") => " << dbg << std::endl;

    ///

    MeCab::scoped_ptr<MeCab::ModelImpl> model(new MeCab::ModelImpl);
    if (!model->open(param)) {
        std::cout << MeCab::getLastError() << std::endl;
        return EXIT_FAILURE;
    }

    std::string ofilename = param.get<std::string>("output");
    if (ofilename.empty()) {
        ofilename = "-";
    }

    const int nbest = param.get<int>("nbest");
    if (nbest <= 0 || nbest > NBEST_MAX) {
        WHAT_ERROR("invalid N value");
    }

    MeCab::ostream_wrapper ofs(ofilename.c_str());
    if (!*ofs) {
        WHAT_ERROR("no such file or directory: " << ofilename);
    }

    if (param.get<bool>("dump-config")) {
        param.dump_config(&*ofs);
        return EXIT_FAILURE;
    }

    if (param.get<bool>("dictionary-info")) {
        for (const MeCab::DictionaryInfo *d = model->dictionary_info();
                d; d = d->next) {
            *ofs << "filename:\t" << d->filename << std::endl;
            *ofs << "version:\t" << d->version << std::endl;
            *ofs << "charset:\t" << d->charset << std::endl;
            *ofs << "type:\t" << d->type   << std::endl;
            *ofs << "size:\t" << d->size << std::endl;
            *ofs << "left size:\t" << d->lsize << std::endl;
            *ofs << "right size:\t" << d->rsize << std::endl;
            *ofs << std::endl;
        }
        return EXIT_FAILURE;
    }

    const std::vector<std::string>& rest_ = param.rest_args();
    std::vector<std::string> rest = rest_;

    if (rest.empty()) {
        rest.push_back("-");
    }

    size_t ibufsize = std::min(MAX_INPUT_BUFFER_SIZE,
                               std::max(param.get<int>
                                        ("input-buffer-size"),
                                        MIN_INPUT_BUFFER_SIZE));

    const bool partial = param.get<bool>("partial");
    if (partial) {
        ibufsize *= 8;
    }

    MeCab::scoped_array<char> ibuf_data(new char[ibufsize]);
    char *ibuf = ibuf_data.get();

    MeCab::scoped_ptr<MeCab::Tagger> tagger(model->createTagger());

    if (!tagger.get()) {
        WHAT_ERROR("cannot create tagger");
    }

    for (size_t i = 0; i < rest.size(); ++i) {
        MeCab::istream_wrapper ifs(rest[i].c_str());
        if (!*ifs) {
            WHAT_ERROR("no such file or directory: " << rest[i]);
        }

        while (true) {
            if (!partial) {
                ifs->getline(ibuf, ibufsize);
            } else {
                std::string sentence;
                MeCab::scoped_fixed_array<char, BUF_SIZE> line;
                for (;;) {
                    if (!ifs->getline(line.get(), line.size())) {
                        ifs->clear(std::ios::eofbit|std::ios::badbit);
                        break;
                    }
                    sentence += line.get();
                    sentence += '\n';
                    if (std::strcmp(line.get(), "EOS") == 0 || line[0] == '\0') {
                        break;
                    }
                }
                std::strncpy(ibuf, sentence.c_str(), ibufsize);
            }
            if (ifs->eof() && !ibuf[0]) {
                return false;
            }
            if (ifs->fail()) {
                std::cerr << "input-buffer overflow. "
                          << "The line is split. use -b #SIZE option." << std::endl;
                ifs->clear();
            }
            const char *r = (nbest >= 2) ? tagger->parseNBest(nbest, ibuf) :
                            tagger->parse(ibuf);
            if (!r)  {
                WHAT_ERROR(tagger->what());
            }
            *ofs << r << std::flush;
        }
    }

    return EXIT_SUCCESS;

#undef WHAT_ERROR
}
Example #12
0
bool Tagger::parse(const Model &model, Lattice *lattice) {
    scoped_ptr<Tagger> tagger(model.createTagger());
    return tagger->parse(lattice);
}
Example #13
0
int main(){
	std::string mp3("/home/mhlzol004/Music/07 Bruno Mars - Natalie.mp3");
	idtag tagger(mp3);
}