GeoPubby  Version 0.1.0.0
MergeDataSource Class Reference

A DataSource that presents an RDF merge of multiple other data sources. More...

Inheritance diagram for MergeDataSource:
Collaboration diagram for MergeDataSource:

Public Member Functions

 MergeDataSource (DataSource... sources)
 
 MergeDataSource (Collection< DataSource > sources)
 
 MergeDataSource (Collection< DataSource > sources, PrefixMapping mustHavePrefixes)
 
boolean canDescribe (String absoluteIRI)
 Indicates whether this data source may have some information about a given IRI. More...
 
Model describeResource (String iri, String language)
 Returns a subgraph of the data source describing one resource. More...
 
Model describeResource (String iri)
 Returns a subgraph of the data source describing one resource. More...
 
Map< Property, Integer > getHighIndegreeProperties (String resourceIRI)
 If describeResource(String) omits properties of high indegree, then those properties must be returned here with the count of arcs. More...
 
Map< Property, Integer > getHighOutdegreeProperties (String resourceIRI)
 If describeResource(String) omits properties of high outdegree, then those properties must be returned here with the count of arcs. More...
 
Model listPropertyValues (String resourceIRI, Property property, boolean isInverse)
 Returns a subgraph of the data source. More...
 
List< Resource > getIndex ()
 A list of IRI resources described in this data source. More...
 
de.fuberlin.wiwiss.pubby.util.AutocompleteEngine< SearchRecordgetLabelIndex ()
 

Public Attributes

final Collection< DataSourcesources
 

Static Public Attributes

static final int MAX_INDEX_SIZE = 1000000
 

Package Functions

private< K > Map< K, Integer > addIntegerMaps (Map< K, Integer > map1, Map< K, Integer > map2)
 

Private Attributes

final PrefixMapping mustHavePrefixes
 

Detailed Description

A DataSource that presents an RDF merge of multiple other data sources.

Can also be initialized with a prefix mapping that will be guaranteed to be defined on all result models.

Constructor & Destructor Documentation

◆ MergeDataSource() [1/3]

MergeDataSource ( DataSource...  sources)
31  {
32  this(Arrays.asList(sources));
33  }
final Collection< DataSource > sources
Definition: MergeDataSource.java:28

References MergeDataSource.sources.

◆ MergeDataSource() [2/3]

MergeDataSource ( Collection< DataSource sources)
35  {
36  this(sources, new PrefixMappingImpl());
37  }

References MergeDataSource.sources.

◆ MergeDataSource() [3/3]

MergeDataSource ( Collection< DataSource sources,
PrefixMapping  mustHavePrefixes 
)
39  {
40  this.sources = sources;
42  }
final PrefixMapping mustHavePrefixes
Definition: MergeDataSource.java:29

References MergeDataSource.mustHavePrefixes, and MergeDataSource.sources.

Member Function Documentation

◆ addIntegerMaps()

private<K> Map<K, Integer> addIntegerMaps ( Map< K, Integer >  map1,
Map< K, Integer >  map2 
)
package
133  {
134  if (map1 == null) return map2;
135  if (map2 == null) return map1;
136  for (K key: map2.keySet()) {
137  int value = map2.get(key);
138  if (value == 0) continue;
139  map1.put(key, map1.containsKey(key) ? map1.get(key) + value : value);
140  }
141  return map1;
142  }

Referenced by MergeDataSource.getHighIndegreeProperties(), and MergeDataSource.getHighOutdegreeProperties().

◆ canDescribe()

boolean canDescribe ( String  absoluteIRI)

Indicates whether this data source may have some information about a given IRI.

If this is false, a client should not bother to call describeResource(String). This method is to allow for optimizations and should respond very fast.

It is also used by the UI to decide whether a click on a resource should go to a Pubby page (if true) or out to the Web (if false).

Parameters
absoluteIRIThe IRI of a resource to be described
Returns
true if this data source might have something about it

Implements DataSource.

45  {
46  for (DataSource source: sources) {
47  if (source.canDescribe(absoluteIRI)) return true;
48  }
49  return false;
50  }

References MergeDataSource.sources.

◆ describeResource() [1/2]

Model describeResource ( String  absoluteIRI)

Returns a subgraph of the data source describing one resource.

This should include both incoming and outgoing triples. However, it should exclude outgoing arcs where the property is a high-outdegree property, and it should exclude incoming arcs where the property is a high-indegree property. If labels for other resources are included in the result, then they will be used.

Parameters
absoluteIRIThe IRI of the resource to be described
Returns
A subgraph of the data source describing the resource.

Implements DataSource.

72  {
73  Model result = ModelFactory.createDefaultModel();
74  for (DataSource source: sources) {
75  if (!source.canDescribe(iri)) continue;
76  ModelUtil.mergeModels(result, source.describeResource(iri));
77  }
78  // Remove any other prefixes that may already be defined for the must-have namespaces
79  for (String prefix: mustHavePrefixes.getNsPrefixMap().keySet()) {
80  String ns = mustHavePrefixes.getNsPrefixURI(prefix);
81  while (result.getNsURIPrefix(ns) != null) {
82  result.removeNsPrefix(result.getNsURIPrefix(ns));
83  }
84  }
85  // Set all the must-have prefix/namespace pairs
86  ModelUtil.mergePrefixes(result, mustHavePrefixes);
87  return result;
88  }

References ModelUtil.mergeModels(), ModelUtil.mergePrefixes(), MergeDataSource.mustHavePrefixes, and MergeDataSource.sources.

◆ describeResource() [2/2]

Model describeResource ( String  absoluteIRI,
String  language 
)

Returns a subgraph of the data source describing one resource.

This should include both incoming and outgoing triples. However, it should exclude outgoing arcs where the property is a high-outdegree property, and it should exclude incoming arcs where the property is a high-indegree property. If labels for other resources are included in the result, then they will be used.

Parameters
absoluteIRIThe IRI of the resource to be described
Returns
A subgraph of the data source describing the resource.

Implements DataSource.

53  {
54  Model result = ModelFactory.createDefaultModel();
55  for (DataSource source: sources) {
56  if (!source.canDescribe(iri)) continue;
57  ModelUtil.mergeModels(result, source.describeResource(iri,language));
58  }
59  // Remove any other prefixes that may already be defined for the must-have namespaces
60  for (String prefix: mustHavePrefixes.getNsPrefixMap().keySet()) {
61  String ns = mustHavePrefixes.getNsPrefixURI(prefix);
62  while (result.getNsURIPrefix(ns) != null) {
63  result.removeNsPrefix(result.getNsURIPrefix(ns));
64  }
65  }
66  // Set all the must-have prefix/namespace pairs
67  ModelUtil.mergePrefixes(result, mustHavePrefixes);
68  return result;
69  }

References ModelUtil.mergeModels(), ModelUtil.mergePrefixes(), MergeDataSource.mustHavePrefixes, and MergeDataSource.sources.

◆ getHighIndegreeProperties()

Map<Property, Integer> getHighIndegreeProperties ( String  resourceIRI)

If describeResource(String) omits properties of high indegree, then those properties must be returned here with the count of arcs.

If high-indegree properties are not omitted, or the resource doesn't have any, then an empty map or null may be returned. Entries with value 0 will be ignored.

Parameters
resourceIRIThe IRI of the resource to be described
Returns
A map containing high-indegree properties with number of arcs for the resource

Implements DataSource.

92  {
93  Map<Property, Integer> result = new HashMap<Property, Integer>();
94  for (DataSource source: sources) {
95  result = addIntegerMaps(result,
96  source.getHighIndegreeProperties(resourceIRI));
97  }
98  return result;
99  }
private< K > Map< K, Integer > addIntegerMaps(Map< K, Integer > map1, Map< K, Integer > map2)
Definition: MergeDataSource.java:133

References MergeDataSource.addIntegerMaps(), and MergeDataSource.sources.

◆ getHighOutdegreeProperties()

Map<Property, Integer> getHighOutdegreeProperties ( String  resourceIRI)

If describeResource(String) omits properties of high outdegree, then those properties must be returned here with the count of arcs.

If high-outdegree properties are not omitted, or the resource doesn't have any, then an empty map or null may be returned. Entries with value 0 will be ignored.

Parameters
resourceIRIThe IRI of the resource to be described
Returns
A map containing high-outdegree properties with number of arcs for the resource

Implements DataSource.

102  {
103  Map<Property, Integer> result = new HashMap<Property, Integer>();
104  for (DataSource source: sources) {
105  result = addIntegerMaps(result,
106  source.getHighOutdegreeProperties(resourceIRI));
107  }
108  return result;
109  }

References MergeDataSource.addIntegerMaps(), and MergeDataSource.sources.

◆ getIndex()

List<Resource> getIndex ( )

A list of IRI resources described in this data source.

Ordering is implementation-defined. Usually a reasonable limit should be applied to the number of resources returned.

Implements DataSource.

124  {
125  List<Resource> result = new ArrayList<Resource>();
126  for (DataSource source: sources) {
127  System.out.println(source);
128  result.addAll(source.getIndex());
129  }
130  return result;
131  }

References MergeDataSource.sources.

◆ getLabelIndex()

Implements DataSource.

145  {
146  System.out.println("MergeDataSource: GetLabelIndex()");
147  for(DataSource ds:sources) {
148  ds.getLabelIndex();
149  }
150  return SearchIndexInstance.getInstance();
151  }

References SearchIndexInstance.getInstance(), and MergeDataSource.sources.

◆ listPropertyValues()

Model listPropertyValues ( String  resourceIRI,
Property  property,
boolean  isInverse 
)

Returns a subgraph of the data source.

It lists the values of a particular property of a particular resource. Where values are blank nodes, a complete description of these anonymous resources must be included.

Parameters
resourceIRIThe resource to be examined
propertyThe property we're interested in
isInverseAre we interested in outgoing arcs (false) or incoming (true)?
Returns
A subgraph of the data source.

Implements DataSource.

113  {
114  Model result = ModelFactory.createDefaultModel();
115  for (DataSource source: sources) {
116  ModelUtil.mergeModels(result,
117  source.listPropertyValues(resourceIRI, property, isInverse));
118  }
119  ModelUtil.mergePrefixes(result, mustHavePrefixes);
120  return result;
121  }

References ModelUtil.mergeModels(), ModelUtil.mergePrefixes(), MergeDataSource.mustHavePrefixes, and MergeDataSource.sources.

Member Data Documentation

◆ MAX_INDEX_SIZE

◆ mustHavePrefixes

final PrefixMapping mustHavePrefixes
private

◆ sources