#!/usr/bin/perl

use strict;
use warnings;

binmode(OUT, ":utf8");


my $tagset = qr/NN|NP|NR|VV|VA|VX|MM|ETN|SN|SW|XP|XS|XR/;

while(<>){
	chomp;
	s/[\n\r]//g;

	next if $_ eq '';
#	next if $_ =~ /^\s*</;

	print $_,"\n" and next if $_ =~ /^\s*</;

	my ($phrase, $wordninfo) = split(/\t/, $_);
	
	$phrase =~ s/\s//g;
	$wordninfo =~ s/\s//g;

	if($wordninfo =~ /\+/){
		my @wordsninfos = split (/\+/, $wordninfo);
		my @words;
		my @infos;
		for(my $i=0;$i<@wordsninfos;$i++){
			if($wordsninfos[$i] =~ /\/\//){
				my $e_word = '/';
				my ($e_info) = ($wordsninfos[$i] =~ /\/\/(.+)/);
				push @infos, $e_info;
				push @words, $e_word;
			}else{
				my ($e_word,$e_info) = split (/\//, $wordsninfos[$i]);
				push @infos, $e_info;
				if($e_info =~ /^$tagset/){
					push @words, $e_word;
				}elsif($e_info =~ /^SP$/){
					push @words, $e_word if $wordsninfos[$i-1] =~ /\/SN/ and $wordsninfos[$i+1] =~ /\/SN/;
				}
			}
		}
		print $phrase,"\t",join('_',@infos),"\t",join('',@words),"\n";
	}
	else{
		if($wordninfo =~ /\/\//){
			my $word = '/';
			my ($info) = ($wordninfo =~ /\/\/(.+)/);
			print $phrase,"\t",$info,"\t",$word,"\n";
		}else{
			my($word, $info) = split (/\//, $wordninfo);
			print $phrase,"\t",$info,"\t",$word,"\n";
		}
	}
}

