topic rename

author:

published:

updated:

May 28, 2009 11:25:15PM UTC

source uri:

Acre Doc /freebase/acre_doc

Handler:

Default Configuration:

Acre Doc /freebase/acre_doc

Handler:

Default Configuration:

Summary


var id = acre.environ.path_info;

/*
* domain = domain where types define tabs
...

Content


var id = acre.environ.path_info;

/*
* domain = domain where types define tabs
* empty = show empty properties
* sort = prop | val
*/
var settings = acre.environ.params;

if (id == '/') { id='/en/bob_dylan'; } // set default topic if there wasn't one passed in the URL settings


// Get "primary types"
//
// If the topic being rendered contains a primary type,
// that type's domain tab should be shown first
// and that tab should be named after the type, not the domain

var primaryTypesRaw = getPrimaryTypes();
var primaryTypes = primaryTypesRaw["/user/robert/topic_view/primary_type_holder/primary_type"];
var primaryType = null;
var primaryDomain = null;

// Get types from special domain that defines tabs
// This domain path is defined as an argument in the invoking URL
//
// The types in this domain each represent a type, and
// the properties in these types define which properties
// are displayed in each tab.
// These properties delegate from properties in commons types

var viewTabMap = getDomainTabOrder();

var tabIndex = 0;
var tabBodyIndex = 0;
var tabOrder = [];
var tabs = {};
var commonProperties = {};


// Get topic data and process properties
var lib = acre.require("/freebase/apps/libraries/topic");
var o = lib.json_for_topic(id);

for (d in o.domains){
var domain = o.domains[d];

// Skip data in user domains (for now)
if(domain.id.match(/^\/user/)) {
continue;
};

// Identify if any of the topic's types are a "primary type"
// Put the matching type as the first in the domain so the properties appear at the top of the tab
if (!primaryType) {
for (t in domain.types) {
for (ind in primaryTypes) {
if (domain.types[t].id == primaryTypes[ind].id) {

// Set the matching primary type and domain for later processing
primaryType = domain.types[t];
primaryDomain = domain.id;

// Move the matching type first in the domain
var typeHold = domain.types[t];
domain.types.splice(t,1);
domain.types.unshift(typeHold);
continue;
}
}
}
}

for (t in domain.types) {

var typeEntry = domain.types[t];
if (typeEntry.id == "/common/topic") {
processCommonTopicType(typeEntry);
} else {
processOtherType(typeEntry, domain);
}
}
}

// If there is a primary type in topic, set it as the first tab

if (primaryDomain) {
for (tab in tabOrder) {
if (tabOrder[tab] == primaryDomain) {
tabOrder.splice(tab,1);
tabOrder.unshift(primaryDomain);
tabs[primaryDomain].name = primaryType.name;
}
}
}

// Set tabs ordering by number of properties
if (settings.sort && settings.sort == 'prop') {
tabOrder.sort(function(a,b) {
return tabs[b].propertyEntries.length - tabs[a].propertyEntries.length;
});

// or set tabs ordering by number of property values
} else if (settings.sort && settings.sort == 'val') {
tabOrder.sort(function(a,b) {
return tabs[b].dataCount - tabs[a].dataCount;
});

// or set property ordering by special type ordering domain
} else if (settings.sort && settings.domain && settings.sort == 'domain') {
tabOrder.sort(function(a,b) {
var aIndex = viewTabMap[a] != null ? viewTabMap[a] : tabs[a].order * 1000;
var bIndex = viewTabMap[b] != null ? viewTabMap[b] : tabs[a].order * 1000;
return aIndex - bIndex;
});
}


// Get primary types
function getPrimaryTypes() {
return (acre.freebase.mqlread({
"id" : "/guid/9202a8c04000641f8000000008f65cd9",
"/user/robert/topic_view/primary_type_holder/primary_type" : [
{
"id" : null,
"name" : null,
"type" : "/type/type",
"domain" : {
"id":null,
"name":null
}
}
]
}).result);
}

// Process properties on /common/topic
function processCommonTopicType(typeEntry) {
for (p in typeEntry.properties) {
var propertyEntry = typeEntry.properties[p];
var dataEntries = propertyEntry.data;
if (dataEntries.length == 0) {
continue;
}
commonProperties[propertyEntry.id] = dataEntries;
}
};

// Process properties on other types
function processOtherType(typeEntry, domain) {
for (p = 0; p < typeEntry.properties.length; p++) {
var propertyEntry = typeEntry.properties[p];
var...

Created by: jdouglas Aug 7, 2008
Last edited by: tsegaran Oct 2, 2009

Recent Discussions about topic

There is no discussion about this document.

Start the Discussion »
Explore the Data
View all the data we have for topic
Flag this Document
Why do you want to flag this document?