Esempio n. 1
0
int main(int argc, char* argv[])
{
	int dstfmt, opt, ret;
	dstfmt = XDF_ANY;

	while((opt = getopt(argc, argv, "t:h")) != -1) {
		switch (opt) {
		case 't':
			dstfmt = interpret_type(optarg);	
			break;

		default:
			print_usage(stdout, argv[0]);
			return (opt == 'h') ? EXIT_SUCCESS : EXIT_FAILURE;
		}
	}

	if (argc - optind != 2) {
		print_usage(stdout, argv[0]);
		return EXIT_FAILURE;
	}

	
	ret = copy_xdf(argv[optind+1], argv[optind], dstfmt);

	return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}
Esempio n. 2
0
	~ListAllAffixes() {
		file->close();
		QString t=interpret_type(type);
		system(QString("sort %1.list >%1_sorted.list ").arg(t).toStdString().data());
		delete file;
		delete dout;
	}
Esempio n. 3
0
/*
 * Run the fsck program on a particular device
 * 
 * If the type is specified using -t, and it isn't prefixed with "no"
 * (as in "noext2") and only one filesystem type is specified, then
 * use that type regardless of what is specified in /etc/fstab.
 * 
 * If the type isn't specified by the user, then use either the type
 * specified in /etc/fstab, or DEFAULT_FSTYPE.
 */
static void fsck_device(char *device, int interactive)
{
	const char *type = 0;
	struct fs_info *fsent;
	int retval;

	if (fstype && strncmp(fstype, "no", 2) &&
	    strncmp(fstype, "opts=", 5) && strncmp(fstype, "loop", 4) && 
	    !strchr(fstype, ','))
		type = fstype;

	if ((fsent = lookup(device))) {
		device = fsent->device;
		interpret_type(fsent);
		if (!type)
			type = fsent->type;
	}
	if (!type)
		type = DEFAULT_FSTYPE;

	num_running++;
	retval = execute(type, device, fsent ? fsent->mountpt : 0,
			 interactive);
	if (retval) {
		fprintf(stderr, _("%s: Error %d while executing fsck.%s "
			"for %s\n"), progname, retval, type, device);
		num_running--;
	}
}
Esempio n. 4
0
Search_by_category::Search_by_category(long category_id)
{
        err=false;
        QSqlQuery temp(db);
        query=temp;
        get_type_of_category(category_id,type);
        QString table = interpret_type(type);
        QString stmt( "SELECT %1_id, category_id, sources, raw_data, POS, description_id %3 FROM %1_category WHERE category_id ='%2' ORDER BY %1_id ASC");
        stmt=stmt.arg(table).arg(category_id).arg((type==STEM?", abstract_categories, lemma_ID":""));
        if (!execute_query(stmt,query)) //will use the local query
                err=true;
}
Esempio n. 5
0
/* Check if we should ignore this filesystem. */
static int ignore(struct fs_info *fs)
{
	const char **ip;
	int wanted = 0;

	/*
	 * If the pass number is 0, ignore it.
	 */
	if (fs->passno == 0)
		return 1;

	/*
	 * If this is a bind mount, ignore it.
	 */
	if (opt_in_list("bind", fs->opts)) {
		fprintf(stderr,
			_("%s: skipping bad line in /etc/fstab: bind mount with nonzero fsck pass number\n"),
			fs->mountpt);
		return 1;
	}

	interpret_type(fs);

	/*
	 * If a specific fstype is specified, and it doesn't match,
	 * ignore it.
	 */
	if (!fs_match(fs, &fs_type_compiled)) return 1;

	/* Are we ignoring this type? */
	for(ip = ignored_types; *ip; ip++)
		if (strcmp(fs->type, *ip) == 0) return 1;

	/* Do we really really want to check this fs? */
	for(ip = really_wanted; *ip; ip++)
		if (strcmp(fs->type, *ip) == 0) {
			wanted = 1;
			break;
		}

	/* See if the <fsck.fs> program is available. */
	if (find_fsck(fs->type) == NULL) {
		if (wanted)
			fprintf(stderr, _("fsck: cannot check %s: fsck.%s not found\n"),
				fs->device, fs->type);
		return 1;
	}

	/* We can and want to check this file system type. */
	return 0;
}
Esempio n. 6
0
	ListAllAffixes(item_types type) {
		this->type=type;

		QString t=interpret_type(type);
		file=new QFile(QString("%1.list").arg(t));
		file->remove();
		if (!file->open(QIODevice::ReadWrite))
		{
                        theSarf->out<<"Error openning file\n";
			return;
		}

		dout=new QTextStream(file);
		dout->setCodec("utf-8");
		map=(type==PREFIX?database_info.map_prefix:database_info.map_suffix);
	}
Esempio n. 7
0
Search_by_item::Search_by_item(item_types type, long long id) {
    QSqlQuery temp(theSarf->db);
    query = temp;
    this->type = type;
    this->id = id;
    QString table = interpret_type(type);

    if (id != -1) {
        name = getColumn(table, "name", id); //will use the global query
        //QString stmt( "SELECT DISTINCT category_id FROM %1_category WHERE %1_id ='%2' ORDER BY category_id ASC");
        QString stmt("SELECT %1_id, category_id, sources, raw_data, POS, description_id %3 FROM %1_category WHERE %1_id ='%2' ORDER BY category_id ASC");
        stmt = stmt.arg(table).arg(id).arg((type == STEM ? ", abstract_categories, lemma_ID" : ""));
        //if (!execute_query(stmt,query)) //will use the local query
        //id=-1; //not really, but because an error took place
        execute_query(stmt, query);
    }
}
Esempio n. 8
0
Search_by_item::Search_by_item(item_types type, QString name, QVector<QString> names) {
    QSqlQuery temp(theSarf->db);
    query = temp;
    this->type = type;
    QString table = interpret_type(type);
    //maybe better here get information about GrammarStem, and its sources and save it, but not a problem, or not??
    QString where;
    int count = 0;
    id = getID(table, name); //will use the global query

    if (id != -1) {
        if (!names.contains(name)) {
            names.append(name);
        }

        for (int i = 0; i < names.count(); i++) {
            int temp_id = getID(table, names[i]); //will use the global query

            if (temp_id != -1) {
                if (count != 0) {
                    where.append(" OR ");
                } else {
                    where.append("WHERE ");
                }

                where.append(QString("%1_id ='%2'").arg(table).arg(temp_id));
                count++;
            }
        }
    }

    if (count == 0) {
        id = -1;
    } else {
        QString stmt("SELECT %1_id, category_id, sources, raw_data, POS, description_id %3 FROM %1_category %2 ORDER BY category_id ASC");
        stmt = stmt.arg(table).arg(where).arg((type == STEM ? ", abstract_categories, lemma_ID" : ""));

        if (!execute_query(stmt, query)) { //will use the local query
            id = -1;    //not really, but because an error took place
        }

        //qDebug() <<stmt;
    }
}
Esempio n. 9
0
Search_by_item::Search_by_item(item_types type, QString name) {
    QSqlQuery temp(theSarf->db);
    query = temp;
    this->type = type;
    this->name = name;
    QString table = interpret_type(type);
    //maybe better here get information about GrammarStem, and its sources and save it, but not a problem, or not??
    id = getID(table, name); //will use the global query

    if (id != -1) {
        //QString stmt( "SELECT DISTINCT category_id FROM %1_category WHERE %1_id ='%2' ORDER BY category_id ASC");
        QString stmt("SELECT %1_id, category_id, sources, raw_data, POS, description_id %3 FROM %1_category WHERE %1_id ='%2' ORDER BY category_id ASC");
        stmt = stmt.arg(table).arg(id).arg((type == STEM ? ", abstract_categories, lemma_ID" : ""));

        if (!execute_query(stmt, query)) { //will use the local query
            id = -1;    //not really, but because an error took place
        }
    }
}
Esempio n. 10
0
static int ignore(struct fs_info *fs)
{
	const char **ip;
	int wanted = 0;

	if (fs->passno == 0)
		return 1;

	if (opt_in_list("bind", fs->opts)) {
		fprintf(stderr,
			_("%s: skipping bad line in /etc/fstab: bind mount with nonzero fsck pass number\n"),
			fs->mountpt);
		return 1;
	}

	interpret_type(fs);

	if (!fs_match(fs, &fs_type_compiled)) return 1;

	
	for(ip = ignored_types; *ip; ip++)
		if (strcmp(fs->type, *ip) == 0) return 1;

	
	for(ip = really_wanted; *ip; ip++)
		if (strcmp(fs->type, *ip) == 0) {
			wanted = 1;
			break;
		}

	
	if (find_fsck(fs->type) == NULL) {
		if (wanted)
			fprintf(stderr, _("fsck: cannot check %s: fsck.%s not found\n"),
				fs->device, fs->type);
		return 1;
	}

	
	return 0;
}
Esempio n. 11
0
/* Check if we should ignore this filesystem. */
static int ignore(struct fs_info *fs)
{
	int wanted;
	char *s;

	/*
	 * If the pass number is 0, ignore it.
	 */
	if (fs->passno == 0)
		return 1;

	interpret_type(fs);

	/*
	 * If a specific fstype is specified, and it doesn't match,
	 * ignore it.
	 */
	if (!fs_match(fs, &fs_type_compiled)) return 1;

	/* Are we ignoring this type? */
	if (index_in_str_array(ignored_types, fs->type) >= 0)
		return 1;

	/* Do we really really want to check this fs? */
	wanted = index_in_str_array(really_wanted, fs->type) >= 0;

	/* See if the <fsck.fs> program is available. */
	s = find_fsck(fs->type);
	if (s == NULL) {
		if (wanted)
			bb_error_msg("cannot check %s: fsck.%s not found",
				fs->device, fs->type);
		return 1;
	}
	free(s);

	/* We can and want to check this file system type. */
	return 0;
}
Esempio n. 12
0
/*
 * Run the fsck program on a particular device
 *
 * If the type is specified using -t, and it isn't prefixed with "no"
 * (as in "noext2") and only one filesystem type is specified, then
 * use that type regardless of what is specified in /etc/fstab.
 *
 * If the type isn't specified by the user, then use either the type
 * specified in /etc/fstab, or DEFAULT_FSTYPE.
 */
static void fsck_device(struct fs_info *fs, int interactive)
{
	const char *type;
	int retval;

	interpret_type(fs);

	if (strcmp(fs->type, "auto") != 0)
		type = fs->type;
	else if (fstype && strncmp(fstype, "no", 2) &&
	    strncmp(fstype, "opts=", 5) && strncmp(fstype, "loop", 4) &&
	    !strchr(fstype, ','))
		type = fstype;
	else
		type = DEFAULT_FSTYPE;

	num_running++;
	retval = execute(type, fs->device, fs->mountpt, interactive);
	if (retval) {
		bb_error_msg("error %d while executing fsck.%s for %s",
						retval, type, fs->device);
		num_running--;
	}
}
Esempio n. 13
0
void drawAffixGraph(item_types type) {
	int last_id=0;
	AffixGraphMap map;
	map.clear();
	QString t=interpret_type(type);
	QQueue<node *> queue;
	node * base=(type==PREFIX?database_info.Prefix_Tree->getFirstNode():database_info.Suffix_Tree->getFirstNode());
	QFile file(QString("%1.dot").arg(t));
	file.remove();
	if (!file.open(QIODevice::ReadWrite))
	{
                theSarf->out<<"Error openning file\n";
		return;
	}

	QTextStream d_out(&file);
	d_out.setCodec("utf-8");
	d_out<<"digraph tree {\n";
	queue.enqueue(base);

	while (!queue.isEmpty())
	{
		node & n=*(queue.dequeue());
		if (n.isLetterNode()) {
			letter_node & l= (letter_node &)n;
			QChar letter=l.getLetter();
			d_out<<"n"<<getGraphID(map,last_id,&n)<<" [label=\""<<(letter!='\0'?letter:'-')<<"\", shape=circle];\n";
		}else {
			result_node & r= (result_node &)n;
		#ifdef SHOW_CATEGORY
			d_out<<"n"<<getGraphID(map,last_id,&n)<<" [label=\""
				#ifdef SHOW_CATEGORY_LABEL
					<<database_info.comp_rules->getCategoryName(r.get_resulting_category_id())
				#endif
					<<"\", shape=rectangle];\n";
		#endif
		#ifdef SHOW_RAW_DATA
			int size=r.raw_datas.size();
			for (int i=0;i<size;i++) {
				d_out<<"r"<<getGraphID(map,last_id,&n)<<"_"<<i<<" [label=\""<<r.raw_datas[i].getActual()<<"\", shape=oval, color=red];\n";
			#ifdef SHOW_CATEGORY
				d_out<<"n"<<getGraphID(map,last_id,&n)
			#else
				d_out<<"n"<<getGraphID(map,last_id,(n.isLetterNode()?&n:(n.getPrevious())))
			#endif
						<<"->"<<"r"<<getGraphID(map,last_id,&n)<<"_"<<i<<";\n";
			}
		#endif
		}
		QVector<letter_node *> l_nodes=n.getLetterChildren();
		QList<result_node *> r_nodes =*n.getResultChildren();
		int size=l_nodes.size();
		for (int i=0; i<size;i++) {
			node * nc=l_nodes[i];
			if (nc!=NULL) {
				queue.enqueue(nc);
			#if defined(SHOW_CATEGORY)
				d_out<<"n"<< getGraphID(map,last_id,&n)<<"->"<<"n"<<getGraphID(map,last_id,nc)<<";\n";
			#elif defined(SHOW_RAW_DATA)
				if (n.isLetterNode())
					d_out<<"n"<< getGraphID(map,last_id,&n)<<"->"<<"n"<<getGraphID(map,last_id,nc)<<";\n";
				else {
					result_node * rn=(result_node*)&n;
					QList<QString> l=rn->raw_datas;
					for (int i=0;i<l.size();i++) {
						d_out<<"r"<<getGraphID(map,last_id,rn)<<"_"<<i<<"->"<<"n"<<getGraphID(map,last_id,nc)<<";\n";
					}
				}
			#else
				d_out<<"n"<< getGraphID(map,last_id,(n.isLetterNode()?&n:(n.getPrevious())))<<"->"<<"n"<<getGraphID(map,last_id,nc)<<";\n";
			#endif

			}
		}

		size=r_nodes.size();
		for (int i=0; i<size;i++) {
			node * nc=r_nodes[i];
			if (nc!=NULL) {
				queue.enqueue(nc);
			#ifdef SHOW_CATEGORY
				d_out<<"n"<<getGraphID(map,last_id,&n)<<"->"<<"n"<<getGraphID(map,last_id,nc)<<";\n";
			#endif
			}
		}

	}
	d_out<<"}\n";
	file.close();
	try{
#ifdef DISPLAY
		system(QString("dot -Tsvg %1.dot -o %1.svg").arg(t).toStdString().data());
		QMainWindow * mw =new QMainWindow(NULL);
		mw->setWindowTitle(QString("%1 Tree").arg(t));
		QScrollArea * sa=new QScrollArea(mw);
		mw->setCentralWidget(sa);
		QLabel *pic=new QLabel(sa);
		pic->setPixmap(QPixmap(QString("./%1.svg").arg(t)));
		sa->setWidget(pic);
		mw->show();
#else
		system(QString("kgraphviewer ./%1.dot -caption \"%1.dot\" &").arg(t).arg(QDir::currentPath()).toStdString().data());
#endif
	}
	catch(...)
	{}
}
Esempio n. 14
0
int tree::build_helper(item_types type, long cat_id1, int size, node * current)
{
    if (size<=0)
		return 0;
    long cat_id2,cat_r_id;
    Search_Compatibility s2((type==PREFIX?AA:CC),cat_id1);
    while (s2.retrieve(cat_id2,cat_r_id))
    {
		QString inflections=s2.getInflectionRules();
		bool isAccept=isAcceptState(type,cat_r_id);
		if (isAccept || hasCompatibleAffixes(type,cat_r_id)) { //dont add to tree branches that have no rules and connect to nothing else that may have rules
			Search_by_category s3(cat_id2);
		#if defined(MEMORY_EXHAUSTIVE) || defined(REDUCE_THRU_DIACRITICS)
			all_item_info inf;
			while(s3.retrieve(inf))	{
					QString name= getColumn(interpret_type(type),"name",inf.item_id);
					name=removeDiacritics(name);
					QString inflectedRawData=inf.raw_data;
					applyRawDataInflections(inflections,name,inflectedRawData); //name and inflectedRawData are changed
				#ifdef MEMORY_EXHAUSTIVE
					node * next=addElement(name,inf.item_id,cat_id2,cat_r_id,isAccept,inf.raw_data,inf.description,current);
				#elif defined(REDUCE_THRU_DIACRITICS)
					node * next;
				#if 0
					if (name.isEmpty() && inf.raw_data.isEmpty() && inf.POS.isEmpty() && inf.description().isEmpty()) {
						result_node * n=dynamic_cast<result_node*>(current);
						inf.item_id=n->get_affix_id();
						inf.category_id=n->get_previous_category_id();
						for (int i=0;i<n->raw_datas.size();i++) {
							inf.raw_data=n->raw_datas[i];
							next=addElement(name,inf.item_id,cat_id2,cat_r_id,isAccept,inf.raw_data,current->parent); //check that
						}
					} else
				#endif
						next=addElement(name,inf.item_id,cat_id2,cat_r_id,isAccept,inf.raw_data,inflectedRawData,inflections,current);
				#endif
		#else
			long long affix_id;
			while(s3.retrieve(affix_id))
			{
					QString name= getColumn(interpret_type(type),"name",affix_id);
					node * next=addElement(name,affix_id,cat_id2,cat_r_id,isAccept,current);

		#endif
					build_helper(type,cat_r_id,size-name.length(),next);
			}
		}
    }
    return 0;
}
#ifdef MEMORY_EXHAUSTIVE
node* tree::addElement(QString letters, long affix_id,long category_id, long resulting_category_id,bool isAccept,QString raw_data,QString description,node * current)
#elif defined (REDUCE_THRU_DIACRITICS)
node* tree::addElement(QString letters, long affix_id,long category_id, long resulting_category_id,bool isAccept,QString raw_data, QString inflected_raw_data, QString descriptionInflectionRule,node * current)
#else
node* tree::addElement(QString letters, long affix_id,long category_id, long resulting_category_id,bool isAccept,node * current)
#endif
{
#if 0
	if (!equal(letters,raw_data))
		raw_data.remove(" ");
#endif
	assert (current->isLetterNode() || equal(letters,inflected_raw_data));
#ifdef LOAD_FROM_FILE
	if (file!=NULL)
	{
		(*file)<<letters<<affix_id<<category_id<<resulting_category_id<<isAccept
			#if defined (REDUCE_THRU_DIACRITICS)
				<<raw_data<<inflected_raw_data<<descriptionInflectionRule
			#elif defined (MEMORY_EXHAUSTIVE)
				<<raw_data<<description
			#endif
				<<generateNodeID(current);
	}
#endif
	//pre-condition: assumes category_id is added to the right place and results in the appropraite resulting_category
	QChar current_letter;
	//QList<letter_node *>* current_letter_children;
	letter_node* matching_letter_node=NULL;
	if (current->isLetterNode() && current!=base) {
	#if 1
		error << "Unexpected Error: provided node was a letter node and not a result one\n";
	#ifdef LOAD_FROM_FILE
		if (file!=NULL)
			(*file)<<generateNodeID(NULL);
	#endif
		return NULL;
	#else
		current_letter='\0';
		goto result;
	#endif
    }
	int i;
    if (letters.count()==0)
    {
		current_letter='\0';
		if (current==base)
			goto result;
    }
    else
		current_letter=letters[0];
    i=0;
    do
    {
		matching_letter_node=current->getLetterChild(current_letter);
		if (matching_letter_node!=NULL)
		{
				current=matching_letter_node;
				i++;
				current_letter=letters[i];
		}
		else
			break;
    }while(i<letters.count());
    if (letters.count()==0 && i==0)
    {
		//add null letter
		letter_node* new_node=new letter_node('\0');
		current->addChild(new_node);
		current=new_node;
		letter_nodes++;
    }
    for (;i<letters.count();i++)
    {
		//add necessary letters
		letter_node* new_node=new letter_node(letters[i]);
		current->addChild(new_node);
		current=new_node;
		letter_nodes++;
    }
result:
	int size=current->getResultChildren()->size();
	for (int i=0;i<size;i++) //check if this result node is already present
    {
		result_node * old_result=current->getResultChildren()->at(i);
		if (old_result->get_previous_category_id()==category_id && old_result->get_resulting_category_id()==resulting_category_id && old_result->get_affix_id()==affix_id)
		{
		#ifdef MEMORY_EXHAUSTIVE
			((result_node*)old_result)->addPair(raw_data,description);
		#elif defined(REDUCE_THRU_DIACRITICS)
			old_result->add_raw_data(raw_data, inflected_raw_data);
			old_result->setInflectionRule(descriptionInflectionRule);
		#endif
		#ifdef LOAD_FROM_FILE
			if (file!=NULL)
				(*file)<<generateNodeID(old_result);
		#endif
			return old_result;
		}
    }
#ifdef MEMORY_EXHAUSTIVE
	result_node * result=new result_node(affix_id,category_id,resulting_category_id,isAccept,raw_data,description);
#elif defined(REDUCE_THRU_DIACRITICS)
	result_node * result=new result_node(affix_id,category_id,resulting_category_id,isAccept,raw_data,inflected_raw_data);
#else
	result_node * result=new result_node(affix_id,category_id,resulting_category_id,isAccept);
#endif
	result->setInflectionRule(descriptionInflectionRule);
    current->addChild(result);
    current=result;
    result_nodes++;
#ifdef LOAD_FROM_FILE
	if (file!=NULL)
		(*file)<<generateNodeID(current);
#endif
    return current;
    //post-condition: returns node of resulting category reached after addition
}

tree::tree()
{
    base= new letter_node('\0');
    letter_nodes=1;
    result_nodes=0;
    isAffix=false;
#ifdef LOAD_FROM_FILE
	file=NULL;
#endif
}
tree::tree(item_types type)
{
    base= new letter_node('\0');
    letter_nodes=1;
    result_nodes=0;
    isAffix=true;
#ifdef LOAD_FROM_FILE
	file=NULL;
#endif
    build_affix_tree(type);
}