Skip to content

Commit

Permalink
Also extract FreeBase and type properties
Browse files Browse the repository at this point in the history
  • Loading branch information
egonw committed Dec 1, 2012
1 parent 2d97235 commit 4d3b823
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 3 deletions.
Expand Up @@ -15,5 +15,6 @@ public class Fields {
public final static String HOMEPAGE = "Homepage";
public final static String IDENTIFIER = "Identifier";
public final static String LABEL = "Label";
public final static String TYPE = "Type";

}
Expand Up @@ -40,6 +40,7 @@
import net.bioclipse.icebear.extractors.properties.DBPediaExtractor;
import net.bioclipse.icebear.extractors.properties.DublinCoreExtractor;
import net.bioclipse.icebear.extractors.properties.FoafExtractor;
import net.bioclipse.icebear.extractors.properties.FreebaseExtractor;
import net.bioclipse.icebear.extractors.properties.OpenMoleculesExtractor;
import net.bioclipse.icebear.extractors.properties.RdfsExtractor;
import net.bioclipse.icebear.extractors.properties.SioExtractor;
Expand Down Expand Up @@ -125,6 +126,7 @@ public void ignore(String resource) {
add(new SioExtractor());
add(new OpenMoleculesExtractor());
add(new DBPediaExtractor());
add(new FreebaseExtractor());
}};
private List<INextURIExtractor> spiders = new ArrayList<INextURIExtractor>() {
private static final long serialVersionUID = 7089854109617759948L; {
Expand Down
@@ -0,0 +1,38 @@
/* Copyright (c) 2012 Egon Willighagen <egon.willighagen@gmail.com>
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contact: http://www.bioclipse.net/
*/
package net.bioclipse.icebear.extractors.properties;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.bioclipse.icebear.business.Entry;
import net.bioclipse.icebear.extractors.AbstractExtractor;
import net.bioclipse.icebear.extractors.IPropertyExtractor;
import net.bioclipse.rdf.business.IRDFStore;

public class FreebaseExtractor extends AbstractExtractor implements IPropertyExtractor {

@Override
public List<Entry> extractProperties(IRDFStore store, String resource) {
List<Entry> props = new ArrayList<Entry>();
Map<String,String> resultMap = new HashMap<String, String>();
addPredicateToMap(store, resultMap, "Average molar mass", resource, "http://rdf.freebase.com/ns/chemistry.chemical_compound.average_molar_mass");
addPredicateToMap(store, resultMap, "Boiling point", resource, "http://rdf.freebase.com/ns/chemistry.chemical_compound.boiling_point");
addPredicateToMap(store, resultMap, "Melting point", resource, "http://rdf.freebase.com/ns/chemistry.chemical_compound.melting_point");
addPredicateToMap(store, resultMap, "Density", resource, "http://rdf.freebase.com/ns/chemistry.chemical_compound.density");
for (String key : resultMap.keySet()) {
String value = resultMap.get(key);
props.add(new Entry(resource, key, value));
}
return props;
}
}
@@ -0,0 +1,35 @@
/* Copyright (c) 2012 Egon Willighagen <egon.willighagen@gmail.com>
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contact: http://www.bioclipse.net/
*/
package net.bioclipse.icebear.extractors.properties;

import java.util.ArrayList;
import java.util.List;

import net.bioclipse.icebear.business.Entry;
import net.bioclipse.icebear.business.Fields;
import net.bioclipse.icebear.extractors.AbstractExtractor;
import net.bioclipse.icebear.extractors.IPropertyExtractor;
import net.bioclipse.rdf.business.IRDFStore;

import com.hp.hpl.jena.vocabulary.RDF;

public class RdfExtractor extends AbstractExtractor implements IPropertyExtractor {

@Override
public List<Entry> extractProperties(IRDFStore store, String resource) {
List<String> types = new ArrayList<String>();
types.addAll(getPredicate(store, resource, RDF.type.toString()));
List<Entry> props = new ArrayList<Entry>();
for (String type : types) {
props.add(new Entry(resource, Fields.TYPE, type));
}
return props;
}
}
Expand Up @@ -24,10 +24,10 @@ public class RdfsExtractor extends AbstractExtractor implements IPropertyExtract

@Override
public List<Entry> extractProperties(IRDFStore store, String resource) {
List<String> labels = new ArrayList<String>();
labels.addAll(getPredicate(store, resource, RDFS.label.toString()));

List<Entry> props = new ArrayList<Entry>();

List<String> labels = new ArrayList<String>();
labels.addAll(getPredicate(store, resource, RDFS.label.toString()));
// the first will do fine, but pick the first English one
for (String label : labels) {
if (label.endsWith("@en")) {
Expand All @@ -37,6 +37,14 @@ public List<Entry> extractProperties(IRDFStore store, String resource) {
props.add(new Entry(resource, Fields.LABEL, label));
}
}

// subclass info
List<String> types = new ArrayList<String>();
types.addAll(getPredicate(store, resource, RDFS.subClassOf.toString()));
for (String type : types) {
props.add(new Entry(resource, Fields.TYPE, type));
}

return props;
}
}

0 comments on commit 4d3b823

Please sign in to comment.