Project

General

Profile

1

    
2
import eu.dnetlib.data.mapreduce.hbase.lodExport.utils.LodConfiguration;
3
import org.json.simple.JSONArray;
4
import org.json.simple.JSONObject;
5
import org.json.simple.parser.JSONParser;
6
import org.json.simple.parser.ParseException;
7

    
8
import java.io.FileInputStream;
9
import java.io.IOException;
10
import java.io.InputStream;
11
import java.util.Arrays;
12
import java.util.Properties;
13

    
14
/**
15
 * Created by eri_k on 5/28/2016.
16
 */
17
public class Test {
18

    
19

    
20
    @org.junit.Test
21
    public void testJson() throws IOException, ParseException {
22
        InputStream in = new FileInputStream("C:\\Users\\eri_k\\workspace\\lodinterlinking\\trunk\\src\\main\\resources\\eu\\dnetlib\\data\\mapreduce\\hbase\\lodExport\\mappings.properties");
23

    
24
        Properties properties = new Properties();
25
        properties.load(in);
26
        in.close();
27

    
28
        JSONParser parser = new JSONParser();
29
        JSONObject object = (JSONObject) parser.parse(properties.getProperty("lod_sourceMappings"));
30
        System.out.println(object.get("result"));
31

    
32
        if (((JSONArray) object.get("result")).toString().contains("http://dbpedia.org/ontology/type"))
33
            System.out.println("lal");
34

    
35

    
36
    }
37

    
38

    
39
    @org.junit.Test
40
    public void testSplit() throws Exception {
41
        String line = "<http://lod.openaire.eu/data/person/doajarticles::dc4862cbad761cd43925c558f89e7d17>	<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>	<http://xmlns.com/foaf/0.1/Person>";
42
        InputStream in = new FileInputStream("C:\\Users\\eri_k\\workspace\\lodinterlinking\\trunk\\src\\main\\resources\\eu\\dnetlib\\data\\mapreduce\\hbase\\lodExport\\mappings.properties");
43

    
44
        Properties properties = new Properties();
45
        properties.load(in);
46
        in.close();
47

    
48
        line = line.replace("<", "").replace(">", "");
49

    
50
        LodConfiguration lodConfiguration = new LodConfiguration();
51
        lodConfiguration.load(properties.getProperty("lod_sourceMappings"));
52

    
53
        String[] Fields = line.toString().split("\t");
54

    
55

    
56
        int i = 1;
57

    
58
        String[] tmp = Fields[0].split("/");
59
        String entity = tmp[4];
60
        String id = Fields[0];
61

    
62
        System.out.println(entity);
63
        System.out.println(id);
64

    
65

    
66
        StringBuilder value = new StringBuilder();
67

    
68
        if (lodConfiguration.entityExists(entity)) {
69
            System.out.println("yeaah");
70
            System.out.println("field is " + Fields[i].replace("/", "\\/"));
71
            System.out.println((((org.json.simple.JSONArray) lodConfiguration.getConfig().get(entity))));
72
            System.out.println((((org.json.simple.JSONArray) lodConfiguration.getConfig().get(entity)).toString().contains(Fields[i].replace("/", "\\/"))));
73

    
74
            while (i < Fields.length - 1) {
75
                if (lodConfiguration.isValidField(entity, Fields[i].replace("/", "\\/"))) {
76
                    //  value.append(Fields[i] + "\t" + Fields[i+1]);
77
                    value.append(Fields[i] + "\t" + Fields[i + 1]);
78
                }
79
                i += 2;
80
            }
81
        }
82
        System.out.println("value is " + value);
83
    }
84
}
    (1-1/1)