[irstlm] 75/78: relative path of files pointed in the configuration file areconsidered relative to the path of the configuration file

Giulio Paci giuliopaci-guest at moszumanska.debian.org
Tue May 17 07:47:08 UTC 2016


This is an automated email from the git hooks/post-receive script.

giuliopaci-guest pushed a commit to tag adaptiveLM.v0.10
in repository irstlm.

commit ee2a72bae65d3d44f4cd3cb9759e1df13646505b
Author: Nicola Bertoldi <bertoldi at fbk.eu>
Date:   Tue Dec 22 08:40:14 2015 +0100

    relative path of files pointed in the configuration file areconsidered relative to the path of the configuration file
---
 src/lmInterpolation.cpp | 15 ++++++++++++++-
 src/lmclass.cpp         | 17 +++++++++++++++++
 src/lmmacro.cpp         | 18 ++++++++++++++++++
 3 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/src/lmInterpolation.cpp b/src/lmInterpolation.cpp
index 6bdbafa..2d1db42 100644
--- a/src/lmInterpolation.cpp
+++ b/src/lmInterpolation.cpp
@@ -48,7 +48,16 @@ namespace irstlm {
 	{
 		VERBOSE(2,"lmInterpolation::load(const std::string &filename,int memmap)" << std::endl);
 		VERBOSE(2," filename:|" << filename << "|" << std::endl);
-		
+		//get parent directory of the configuration file
+		//we assume that the parent directory must be prefixed to the filenames (if relative) pointed in the configuration file
+		std::string parent_dir=filename;
+
+		//remove path information
+		std::string::size_type p = parent_dir.rfind('/');
+		if (p != 0 && ((p+1) < parent_dir.size())){
+			parent_dir.erase(p+1,std::string::npos);
+		}
+
 		std::stringstream ss_format;
 		
 		ss_format << "LMINTERPOLATION number_of_models\nweight_of_LM_1 filename_of_LM_1 [inverted]\nweight_of_LM_2 filename_of_LM_2 [inverted]\n...\n";
@@ -146,6 +155,10 @@ namespace irstlm {
 				VERBOSE(2,"i:" << i << " name.str():|" << name.str() << "| m_name[i]:|" << m_name[i] << "|" << endl);
 			}
 			m_file[i] = words[idx_file];
+			p = m_file[i].find('/');
+			if (p != 0){ //path of class filename is relative; hence, add parent path of the configuration file
+				m_file[i] = parent_dir+m_file[i];
+			}
 			
 			VERBOSE(2,"lmInterpolation::load(const std::string &filename,int mmap) i:" << i << " m_name:|"<< m_name[i] << "|" " m_file:|"<< m_file[i] << "| isadaptive:|" << m_isadaptive << "|" << std::endl);
 			
diff --git a/src/lmclass.cpp b/src/lmclass.cpp
index bcefc8e..4964597 100644
--- a/src/lmclass.cpp
+++ b/src/lmclass.cpp
@@ -68,6 +68,15 @@ namespace irstlm {
 	void lmclass::load(const std::string &filename,int memmap)
 	{
 		VERBOSE(2,"lmclass::load(const std::string &filename,int memmap)" << std::endl);
+		//get parent directory of the configuration file
+		//we assume that the parent directory must be prefixed to the filenames (if relative) pointed in the configuration file
+		std::string parent_dir=filename;
+
+		//remove path information
+		std::string::size_type p = parent_dir.rfind('/');
+		if (p != 0 && ((p+1) < parent_dir.size())){
+			parent_dir.erase(p+1,std::string::npos);
+		}
 		
 		//get info from the configuration file
 		fstream inp(filename.c_str(),ios::in|ios::binary);
@@ -86,6 +95,10 @@ namespace irstlm {
 		if (inp.getline(line,MAX_LINE,'\n')) {
 			tokenN = parseWords(line,words,LMCLASS_MAX_TOKEN);
 			lmfilename = words[0];
+			p = lmfilename.find('/');
+			if (p != 0){ //path of LM is relative; hence, add parent path of the configuration file
+				lmfilename = parent_dir+lmfilename;
+			}
 		} else {
 			error((char*)"ERROR: wrong header format of configuration file\ncorrect format: LMCLASS LM_order\nfilename_of_LM\nfilename_of_map");
 		}
@@ -94,6 +107,10 @@ namespace irstlm {
 		if (inp.getline(line,MAX_LINE,'\n')) {
 			tokenN = parseWords(line,words,LMCLASS_MAX_TOKEN);
 			W2Cdict = words[0];
+			p = W2Cdict.find('/');
+			if (p != 0){ //path of W2C is relative; hence, add parent path of the configuration file
+				W2Cdict = parent_dir+W2Cdict;
+			}
 		} else {
 			error((char*)"ERROR: wrong header format of configuration file\ncorrect format: LMCLASS LM_order\nfilename_of_LM\nfilename_of_map");
 		}
diff --git a/src/lmmacro.cpp b/src/lmmacro.cpp
index ec7ec9e..5a24eb6 100644
--- a/src/lmmacro.cpp
+++ b/src/lmmacro.cpp
@@ -65,6 +65,15 @@ namespace irstlm {
 	void lmmacro::load(const std::string &filename,int memmap)
 	{
 		VERBOSE(2,"lmmacro::load(const std::string &filename,int memmap)" << std::endl);
+		//get parent directory of the configuration file
+		//we assume that the parent directory must be prefixed to the filenames (if relative) pointed in the configuration file
+		std::string parent_dir=filename;
+
+		//remove path information
+		std::string::size_type p = parent_dir.rfind('/');
+		if (p != 0 && ((p+1) < parent_dir.size())){
+			parent_dir.erase(p+1,std::string::npos);
+		}
 		
 		//get info from the configuration file
 		fstream inp(filename.c_str(),ios::in|ios::binary);
@@ -106,6 +115,10 @@ namespace irstlm {
 		if (inp.getline(line,MAX_LINE,'\n')) {
 			tokenN = parseWords(line,words,MAX_TOKEN_N_MAP);
 			lmfilename = words[0];
+			p = lmfilename.find('/');
+			if (p != 0){ //path of LM is relative; hence, add parent path of the configuration file
+				lmfilename = parent_dir+lmfilename;
+			}
 		} else
 			error((char*)"ERROR: wrong format of configuration file\ncorrect format: LMMACRO lmsize field [true|false]\nfilename_of_LM\nfilename_of_map (optional)");
 		
@@ -113,6 +126,11 @@ namespace irstlm {
 		if (inp.getline(line,MAX_LINE,'\n')) {
 			tokenN = parseWords(line,words,MAX_TOKEN_N_MAP);
 			mapfilename = words[0];
+                        p = mapfilename.find('/');
+                        if (p != 0){ //path of map is relative; hence, add parent path of the configuration file
+				mapfilename = parent_dir+mapfilename;
+			}
+
 			mapFlag = true;
 		} else {
 			mapFlag = false;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/irstlm.git



More information about the debian-science-commits mailing list