#!/usr/bin/perl

###########################
### Autor: Sebastian Enger / B.Sc. 
### Copyright: Sebastian Enger
### Licence: BSD
### Version: 1.1.b  - 20080716@19.Uhr
### Contact: sebastian.enger@gmail.com | icq: 135846444
### Latest Version: PENDRIVE:\Programming\Perl\IncrementalBackup
###########################

use strict;
use Data::Dumper;
use MongoDB;
use MongoDB::OID;
 
# Connection
#my $connection = MongoDB::Connection->new('mongodb://localhost:27017');
my $connection     = MongoDB::MongoClient->new(host => 'localhost', port => 27017);
##$connection->authenticate ('database_name', 'user', 'password');

# Database
my $database   = $connection->get_database('OneTipp');

# Collection
my $collection = $database->get_collection('B2Cv2');
 
# Query
my $result = $collection->find({});
my $count = 0;

while (my $cursor = $result->next) {

	my $desc = $cursor->{'desc'};
	my $deco = $cursor->{'deco'};
	my $loca = $cursor->{'loca'};
	my $othr = $cursor->{'othr'};
	my $infa = $cursor->{'infa'};
	#my $content = $desc.$deco.$loca.$othr.$infa;
	#next if (length($content)<150);
	foreach my $entry ($desc,$deco,$loca,$othr,$infa){
		my @sentences = split(/(?<=[.?!])\s+(?=\p{Lu})/s, $entry);
		foreach my $sent (@sentences){
			$sent =~ s/\n//ig;
			$sent =~ s/\t//ig;
			$sent =~ s/\r//ig;
			$sent =~ s/\\n//ig;
			$sent =~ s/\\t//ig;
			$sent =~ s/\\r//ig;
			
			$sent =~ s/a data-toggle//ig;
			$sent =~ s/ollapsedata-parent=href=//ig;
			$sent =~ s/>//ig;
			$sent =~ s/=//ig;
			$sent =~ s/\"//ig;
			
			next if (length($sent)<7);
			print "$count Sentences: $sent\n";
			my @words = split("\s{1,}", $sent);
			open(W,"+>>./woerterliste.txt");
				print W join("\n", @words);
			close W;
			system("echo $sent|python Textprocessing.py");
			$count++;
		}
	}
}
exit(1);	

#1. Sätze bilden
#2. Pos Tagger
#3. NER Tagger
#4. Nomensätze
#5. Worter zählen