List<Double> weights = new ArrayList<Double>();
HashMap<String, LinkFrequency> sourceTargetLinkFrequency =
new HashMap<String, LinkFrequency>();
LinkFrequency lf1, lf2;
String key, key1, key2;
String linkUri;
for (DefaultLink link : this.graphBuilder.getGraph().edgeSet()) {
linkUri = link.getUri();
if (!linkUri.equalsIgnoreCase(Uris.DEFAULT_LINK_URI)) {
if (link.getTarget() instanceof InternalNode && !linkUri.equalsIgnoreCase(Uris.RDFS_SUBCLASS_URI)) {
key = "domain:" + link.getSource().getLabel().getUri() + ",link:" + linkUri + ",range:" + link.getTarget().getLabel().getUri();
Integer count = this.graphBuilder.getLinkCountMap().get(key);
if (count != null)
this.graphBuilder.changeLinkWeight(link, ModelingParams.PATTERN_LINK_WEIGHT - ((double)count / (double)this.graphBuilder.getNumberOfModelLinks()) );
}
continue;
}
key1 = link.getSource().getLabel().getUri() +
link.getTarget().getLabel().getUri();
key2 = link.getTarget().getLabel().getUri() +
link.getSource().getLabel().getUri();
lf1 = sourceTargetLinkFrequency.get(key1);
if (lf1 == null) {
lf1 = this.graphBuilder.getMoreFrequentLinkBetweenNodes(link.getSource().getLabel().getUri(), link.getTarget().getLabel().getUri());
sourceTargetLinkFrequency.put(key1, lf1);
}
lf2 = sourceTargetLinkFrequency.get(key2);
if (lf2 == null) {
lf2 = this.graphBuilder.getMoreFrequentLinkBetweenNodes(link.getTarget().getLabel().getUri(), link.getSource().getLabel().getUri());
sourceTargetLinkFrequency.put(key2, lf2);
}
int c = lf1.compareTo(lf2);
String id = null;
if (c > 0) {
sources.add(link.getSource());
targets.add(link.getTarget());
id = LinkIdFactory.getLinkId(lf1.getLinkUri(), link.getSource().getId(), link.getTarget().getId());
if (link instanceof ObjectPropertyLink)
newLinks.add(new ObjectPropertyLink(id, new Label(lf1.getLinkUri()), ((ObjectPropertyLink) link).getObjectPropertyType()));
else if (link instanceof SubClassLink)
newLinks.add(new SubClassLink(id));
weights.add(lf1.getWeight());
} else if (c < 0) {
sources.add(link.getTarget());
targets.add(link.getSource());
id = LinkIdFactory.getLinkId(lf2.getLinkUri(), link.getSource().getId(), link.getTarget().getId());