import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.lambdaworks.redis.RedisURI;
import com.lambdaworks.redis.cluster.RedisAdvancedClusterConnection;
import com.lambdaworks.redis.cluster.RedisClusterClient;
import eu.dnetlib.data.mapreduce.hbase.lodExport.utils.blocking.Tokenizer;
import eu.dnetlib.data.mapreduce.hbase.lodExport.utils.configuration.Properties;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;

public class Test {


    @org.junit.Test
    public void testrecods() {
        String recordId = " id\thttp://lod.openaire.eu/data/result/doajarticles::1ba2cc76a1da1b039aeafb6da70543b9 http://lod.openaire.eu/vocab/resultSubject \"Social Sciences\" .,";

        recordId = "<http://lod.openaire.eu/data/result/od_______162::3147f9e84fde4d4599a45b10e6b7dffb> <http://purl.org/dc/terms/publisher> \"EDP Sciences\" ";


        String regex = "\\s+(?=((\\\\[\\\\\"]|[^\\\\\"])*\"(\\\\[\\\\\"]|[^\\\\\"])*\")*(\\\\[\\\\\"]|[^\\\\\"])*$)";
        //System.out.println(recordId.replaceAll(regex, "\t"));


        //recordId=recordId.replaceAll(regex, "\t");
        recordId = recordId.replaceAll(" +([?:]) +", "\t");
        // System.out.println(recordId);


        String[] split = recordId.split("\t");
        for (String s : split) {

            System.out.println("each");
            System.out.println(s);
        }


        String myLine = "<http://lod.openaire.eu/data/result/doajarticles::57a7815dea6ce88034f6cd9e85abf08b> <http://www.w3.org/2002/07/owl#sameAs> <http://dblp.l3s.de/d2r/resource/publications/journals/bmcbi/KestlerMKBGLKZW08> .\n";

        System.out.println(Arrays.toString(myLine.split(" ")));
    }


    @org.junit.Test
    public void writeToRedis() throws Exception {

        RedisURI redisUri = RedisURI.Builder.redis("83.212.110.197").withPort(6379).build();
        RedisClusterClient clusterClient = RedisClusterClient.create(redisUri);
        RedisAdvancedClusterConnection<String, String> connection = clusterClient.connectCluster();

        connection.set("a", "b");
    }

    @org.junit.Test
    public void split() {
        String record = "id\t<http://dblp.l3s.de/d2r/resource/publications/journals/automatica/Daniel-BerheU98>,<http://www.w3.org/2000/01/rdf-schema#label>\t\"Bilinear Continuous-Time Systems Identification via Hartley-Based Modulating Functions.\",<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>\t<http://xmlns.com/foaf/0.1/Document>,<http://purl.org/dc/terms/identifier>\t\"DOI 10.1016%2FS0005-1098%2897%2900216-1\",<http://purl.org/dc/terms/issued>\t\"1998\",";
        String[] Fields = record.split(",");
        System.out.println("fields are " + Fields);
        System.out.println("index is " + Fields[0].indexOf("\t"));
        String recordId = Fields[0].substring(Fields[0].indexOf("\t"));
        String subject = recordId.substring(record.indexOf("_") + 1);
        System.out.println(recordId);
        System.out.println(subject);

    }


    @org.junit.Test()
    public void testPrime() {
        StringBuilder builder = new StringBuilder();
        List<String> strings = parseFieldsAndGenerateTokens(builder);
        System.out.println(strings);

    }

    protected List<String> parseFieldsAndGenerateTokens(StringBuilder id) {
        String result = "<http://lod.openaire.eu/data/result/acm_________::0e9512ea58c7ddf4115f6a56dee86abc>\t<http://purl.org/dc/terms/identifier>\t\"10.1145/1877937.1877943\"\t.\t<http://lod.openaire.eu/data/result/acm_________::0e9512ea58c7ddf4115f6a56dee86abc>\t<http://purl.org/dc/terms/identifier>\t\"acm_________::0e9512ea58c7ddf4115f6a56dee86abc\"\t.\t<http://lod.openaire.eu/data/result/acm_________::0e9512ea58c7ddf4115f6a56dee86abc>\t<http://purl.org/dc/terms/identifier>\t\"1877943\"\t.\t<http://lod.openaire.eu/data/result/acm_________::0e9512ea58c7ddf4115f6a56dee86abc>\t<http://www.eurocris.org/ontologies/cerif/1.3#name>\t\"Automatic event based indexing of multimedia content using a joint content event model\"\t.\t<http://lod.openaire.eu/data/result/acm_________::0e9512ea58c7ddf4115f6a56dee86abc>\t<http://lod.openaire.eu/vocab/year>\t\"2010\"\t.\t";
        String[] triples = result.split(Properties.LINE_DELIM);

        List<String> tokenList = new ArrayList<>();

        for (String triple : triples) {
            String[] fields = triple.split(Properties.FIELD_DELIM);
            if (fields.length == 3) {
                if (id.length() < 1) {
                    id.append("source_").append(fields[0]);
                }
                String property = fields[1];
                String value = fields[2];

                if (property.equals("<http://purl.org/dc/terms/identifier>")) {
                    System.out.println("Value is " + value);
                    tokenList.add(value.replace("\"", ""));
                }
            }

        }
        return tokenList;
    }
}
