All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ontology2.bakemono.baseKBToDBpedia.BaseKBToDBpediaMapper Maven / Gradle / Ivy

There is a newer version: 3.2
Show newest version
package com.ontology2.bakemono.baseKBToDBpedia;

import com.ontology2.bakemono.primitiveTriples.PrimitiveTriple;
import com.ontology2.bakemono.primitiveTriples.PrimitiveTripleCodec;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

import static com.ontology2.bakemono.util.StatelessIdFunctions.dbpediaEscape;
import static com.ontology2.bakemono.util.StatelessIdFunctions.unescapeKey;

public class BaseKBToDBpediaMapper extends Mapper {
    final PrimitiveTripleCodec codec=new PrimitiveTripleCodec();

    @Override
    protected void setup(Mapper.Context context) throws IOException, InterruptedException {
        super.setup(context);
    }

    @Override
    protected void map(LongWritable key, Text value, Mapper.Context context) throws IOException, InterruptedException {
        PrimitiveTriple pt=codec.decode(value.toString());
        final String prefix = "/wikipedia/en_title/";

        if(pt.getPredicate().equals("")) {
            String fbKey=pt.getObject();
            if (fbKey.startsWith("\"") || fbKey.endsWith("\"")) {
                fbKey=fbKey.substring(1,fbKey.length()-1);

                if(fbKey.startsWith(prefix)) {
                    String wikiKey=fbKey.substring(prefix.length());
                    String dbpediaURI="http://dbpedia.org/resource/"+mapKey(wikiKey);
                    context.write(
                            new Text(pt.getSubject()),
                            new Text("\t<"+dbpediaURI+">\t.")
                    );
                }
            }
        }
    }

    public static String mapKey(String wikiKey) {
        return dbpediaEscape(unescapeKey(wikiKey));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy