Project

General

Profile

« Previous | Next » 

Revision 43098

Added by Eri Katsari almost 8 years ago

View differences:

TargetMapper.java
24 24
        TARGET_ENTITIES,
25 25
    }
26 26

  
27

  
28 27
    @Override
29 28
    protected void setup(Context context) throws IOException, InterruptedException {
30
        //lodConfiguration = new LodConfiguration();
31
        // lodConfiguration.load(context.getConfiguration().get("lod.targetMappings"));
32
        //delim = context.getConfiguration().get("lod.delim");
29
        lodConfiguration = new LodConfiguration();
30
        lodConfiguration.load(context.getConfiguration().get("lod.sourceMappings"));
33 31
    }
34 32

  
35 33

  
36 34
    @Override
37 35
    protected void map(final LongWritable keyIn, final Text result, final Context context) throws IOException {
38 36

  
39
    /*    try {
37
        try {
38
            //get ID - output source_recordID so we can group by id and get all props of a record
39
            StringBuffer value = new StringBuffer();
40 40

  
41
            //TODO remove this and append <,> to all fields in mappings
42
            String[] Fields = result.toString().replace("<", "").replace(">", "").split("\t");
41 43

  
42
            StringBuffer value = new StringBuffer();
43
            String[] Fields = result.toString().split(delim);
44
            //here addd all  fields as array props and append "\t"
45
            // betweeen them so we can write directly to output
46
            //DO NOT enter id- we'll get it from key output
44 47

  
45

  
46 48
            int i = 1;
47
            String entity = Fields[0];
49
            //extract entity type from subject
50
            String[] tmp = Fields[0].split("/");
51
            String type = tmp[4];
52
            String subject = Fields[0];
48 53

  
49
            if (lodConfiguration.entityExists(entity)) {
54
            if (lodConfiguration.entityExists(type)) {
55

  
50 56
                while (i < Fields.length - 1) {
51
                    if (lodConfiguration.isValidField(entity, Fields[i])) {
52
                        value.append(Fields[i] + "\t" + Fields[i + 1]);
57
                    String field = Fields[i];
58
                    String fieldValue = Fields[i + 1];
59

  
60
                    // if (lodConfiguration.isValidField(type, field.replace("/", "\\/")))
61
                    {
62

  
63
                        value.append(field + "\t" + fieldValue).append(",");
53 64
                    }
54 65
                    i += 2;
55 66
                }
56
                // write out source_ID as key, and rest of props as value
57
                Text key = new Text("target_" + Fields[0]);
58
                context.write((key), new Text(value.toString()));
59
                context.getCounter(ENTITIES_COUNTER.TARGET_ENTITIES).increment(1);
67

  
68
                // write out type,source_ID as key, and rest of props as value
69
                //key = person, <http://lod.openaire.eu/data/person/od______1108::ac127c39675469b355dc4f2aa4b301fd>
70

  
71
                Text key = new Text("TARGET" + "," + type + "," + subject);
72
                context.write(key, new Text(value.toString()));
73
                context.getCounter(SourceMapper.ENTITIES_COUNTER.SOURCE_ENTITIES).increment(1);
60 74
            }
61 75
        } catch (Exception e) {
62 76
            log.error("Error writing entity to M/R output", e);
63 77
        }
64
*/
65 78

  
66

  
67 79
    }
68 80

  
69 81

  

Also available in: Unified diff