- improvement for autotagger (is now able to create/detect multi word tags e.g. 'open source') git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@8031 6c8d7289-2bf4-0310-a012-ef5d649a1542pull/1/head
parent
2f03186252
commit
5f7dbe1c42
@ -0,0 +1,72 @@
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.EnumMap;
|
||||
import net.yacy.cora.protocol.RequestHeader;
|
||||
import net.yacy.document.Document;
|
||||
import net.yacy.document.Parser.Failure;
|
||||
import net.yacy.kelondro.data.meta.DigestURI;
|
||||
import net.yacy.search.Switchboard;
|
||||
import de.anomic.data.UserDB;
|
||||
import de.anomic.data.ymark.YMarkAutoTagger;
|
||||
import de.anomic.data.ymark.YMarkEntry;
|
||||
import de.anomic.data.ymark.YMarkMetadata;
|
||||
import de.anomic.data.ymark.YMarkTables;
|
||||
import de.anomic.data.ymark.YMarkUtil;
|
||||
import de.anomic.server.serverObjects;
|
||||
import de.anomic.server.serverSwitch;
|
||||
|
||||
public class get_metadata {
|
||||
|
||||
static serverObjects prop;
|
||||
|
||||
public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
|
||||
final Switchboard sb = (Switchboard) env;
|
||||
prop = new serverObjects();
|
||||
final UserDB.Entry user = sb.userDB.getUser(header);
|
||||
final boolean isAdmin = (sb.verifyAuthentication(header, true));
|
||||
final boolean isAuthUser = user!= null && user.hasRight(UserDB.AccessRight.BOOKMARK_RIGHT);
|
||||
|
||||
if(isAdmin || isAuthUser) {
|
||||
final String bmk_user = (isAuthUser ? user.getUserName() : YMarkTables.USER_ADMIN);
|
||||
try {
|
||||
final String url = post.get(YMarkEntry.BOOKMARK.URL.key());
|
||||
YMarkMetadata meta = new YMarkMetadata(new DigestURI(url), sb.indexSegments);
|
||||
final Document document = meta.loadDocument(sb.loader);
|
||||
final EnumMap<YMarkMetadata.METADATA, String> metadata = meta.loadMetadata();
|
||||
|
||||
prop.putXML("title", metadata.get(YMarkMetadata.METADATA.TITLE));
|
||||
prop.putXML("desc", metadata.get(YMarkMetadata.METADATA.DESCRIPTION));
|
||||
|
||||
prop.put("keywords", putTags(document.dc_subject(','), "keywords"));
|
||||
prop.put("autotags", putTags(YMarkAutoTagger.autoTag(document, 5, sb.tables.bookmarks.getTags(bmk_user)), "autotags"));
|
||||
|
||||
} catch (MalformedURLException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (Failure e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
prop.put(YMarkTables.USER_AUTHENTICATE,YMarkTables.USER_AUTHENTICATE_MSG);
|
||||
}
|
||||
// return rewrite properties
|
||||
return prop;
|
||||
}
|
||||
|
||||
public static int putTags(final String tagString, final String var) {
|
||||
final String list[] = tagString.split(YMarkUtil.TAGS_SEPARATOR);
|
||||
int count = 0;
|
||||
for (final String element : list) {
|
||||
final String tag = element;
|
||||
if (!tag.equals("")) {
|
||||
prop.putXML(var+"_"+count+"_tag", tag);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
<?xml version='1.0' encoding="UTF-8" standalone='yes'?>
|
||||
<info>
|
||||
<title>#[title]#</title>
|
||||
<desc>#[desc]#</desc>
|
||||
<keywords>
|
||||
#{keywords}#<tag name="#[tag]#" />
|
||||
#{/keywords}#
|
||||
</keywords>
|
||||
<autotags>
|
||||
#{autotags}#<tag name="#[tag]#" />
|
||||
#{/autotags}#
|
||||
</autotags>
|
||||
</info>
|
@ -0,0 +1,98 @@
|
||||
/* Initialize Bookmark Actions */
|
||||
function bm_action(com,grid) {
|
||||
if (com=='Delete') {
|
||||
var check = confirm('Delete ' + $('.trSelected',grid).length + ' bookmark(s)?');
|
||||
if(check == true) {
|
||||
$('.trSelected',grid).each(function(){
|
||||
var url = "/api/ymarks/delete_ymark.xml?id="+$(this).find('td :first').text();
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: url,
|
||||
dataType: 'xml',
|
||||
success: function(xml) {
|
||||
$('#ymarks_flexigrid').flexReload();
|
||||
}
|
||||
}); // close $.ajax(
|
||||
}); //close each(
|
||||
}
|
||||
}
|
||||
else if (com=='Add') {
|
||||
$('#bmaddform').resetForm();
|
||||
$("#bm_url").blur(function() {
|
||||
var url = $("input[name='bm_url']").getValue();
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: "/api/ymarks/get_metadata.xml?url="+url,
|
||||
dataType: "xml",
|
||||
success: function(xml) {
|
||||
var title = $(xml).find('title').text();
|
||||
$("input[name='bm_title']").setValue(title);
|
||||
var desc = $(xml).find('desc').text();
|
||||
$("textarea[name='bm_desc']").setValue(desc);
|
||||
|
||||
var autotags = $(xml).find('autotags')
|
||||
var tags = "";
|
||||
$(autotags).find('tag').each(function(){
|
||||
tags = tags + "," + $(this).attr('name');
|
||||
});
|
||||
$("input[name='bm_tags']").setValue(tags);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
$("#ymarks_add_dialog").dialog('open');
|
||||
}
|
||||
else if (com=='Edit') {
|
||||
if ($('.trSelected',grid).length > 1) {
|
||||
alert("Editing of more than one selected bookmark is currently not supportet!");
|
||||
return false;
|
||||
}
|
||||
$("input[name='bm_url']").setValue($('.trSelected',grid).find('.url').text());
|
||||
$("input[name='bm_title']").setValue($('.trSelected',grid).find('h3.linktitle').text().trim());
|
||||
$("textarea[name='bm_desc']").setValue($('.trSelected',grid).find('p.desc').text().trim());
|
||||
$("input[name='bm_tags']").setValue($('.trSelected',grid).find('p.tags').text().trim().replace(/,\s/g,","));
|
||||
$("input[name='bm_path']").setValue($('.trSelected',grid).find('p.folders').text().replace(/,\s/g,","));
|
||||
$("select[name='bm_public']").setValue($('.trSelected',grid).find('img').attr('alt'));
|
||||
$("#ymarks_add_dialog").dialog('open');
|
||||
}
|
||||
else {
|
||||
alert("Sorry, the function you have requested is not yet available!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function bm_dialog() {
|
||||
/* Initialize Bookmark Dialog */
|
||||
$("#ymarks_add_dialog").dialog({
|
||||
autoOpen: false,
|
||||
height: 420,
|
||||
width: 340,
|
||||
position: ['top',100],
|
||||
modal: true,
|
||||
resizable: false,
|
||||
buttons: {
|
||||
OK: function() {
|
||||
var url = $("input[name='bm_url']").getValue();
|
||||
var title = $("input[name='bm_title']").getValue();
|
||||
var desc = $("textarea[name='bm_desc']").getValue();
|
||||
var tags = $("input[name='bm_tags']").getValue()
|
||||
var path = $("input[name='bm_path']").getValue();
|
||||
var pub = $("select[name='bm_public']").getValue();
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/api/ymarks/add_ymark.xml",
|
||||
data: "url="+url+"&title="+title+"&desc="+desc+"&tags="+tags+"&folders="+path+"&public="+pub,
|
||||
dataType: "xml",
|
||||
success: function(xml) {
|
||||
$('#bmaddform').resetForm();
|
||||
$("#bm_url").unbind('blur');
|
||||
$("#ymarks_add_dialog").dialog("close");
|
||||
$('#ymarks_flexigrid').flexReload();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
} ,
|
||||
Cancel: function() { $("#ymarks_add_dialog").dialog("close"); }
|
||||
}
|
||||
});
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
/* Initialize Tag Actions */
|
||||
function tag_action(com,grid) {
|
||||
if (com=='Add') {
|
||||
flex = grid;
|
||||
$('#tagaddform').resetForm();
|
||||
$("#tagadd").dialog('open');
|
||||
} else {
|
||||
$('#tageditform').resetForm();
|
||||
$("#tagedit").dialog('open');
|
||||
}
|
||||
};
|
@ -0,0 +1,139 @@
|
||||
HTMLenc = function(s) {
|
||||
return $('<div/>').text(s).html();
|
||||
}
|
||||
$(document).ready(function() {
|
||||
|
||||
var height=document.documentElement.clientHeight - 200;
|
||||
|
||||
/* Initialize Bookmark Dialog */
|
||||
bm_dialog();
|
||||
|
||||
/* Initialize Flexigrid */
|
||||
$('#ymarks_flexigrid').flexigrid({
|
||||
url: '/api/ymarks/get_ymark.json',
|
||||
dataType: 'json',
|
||||
method: 'GET',
|
||||
colModel: [
|
||||
{display: 'Hash', name : 'hash', width : 50, sortable : false, align: 'center', hide: true},
|
||||
{display: 'Public', name : 'public', width : 25, sortable : true, align: 'center'},
|
||||
{display: 'Title', name : 'title', width : 400, sortable : true, align: 'left'},
|
||||
{display: 'Tags', name : 'tags', width : 160, sortable : false, align: 'left'},
|
||||
{display: 'Folders', name : 'folders', width : 160, sortable : true, align: 'left', hide: true},
|
||||
{display: 'Date added', name : 'date_added', width : 100, sortable : true, align: 'left'},
|
||||
{display: 'Date visited', name : 'date_visited', width : 100, sortable : true, align: 'left'}
|
||||
],
|
||||
buttons: [
|
||||
{name: '...', bclass: 'burst', onpress: function() {
|
||||
$('#ymarks_flexigrid').flexOptions({
|
||||
sortname: "title",
|
||||
sortorder: "asc",
|
||||
query: ".*",
|
||||
qtype: "title"
|
||||
});
|
||||
$('#ymarks_flexigrid').flexReload();
|
||||
}},
|
||||
{separator: true},
|
||||
{name: 'Add', bclass: 'bookmark', onpress: bm_action},
|
||||
{name: 'Edit', bclass: 'edit', onpress: bm_action},
|
||||
{name: 'Delete', bclass: 'delete', onpress: bm_action},
|
||||
{separator: true},
|
||||
{name: 'Crawl', bclass: 'crawl', onpress: bm_action},
|
||||
{separator: true},
|
||||
{name: 'Add', bclass: 'addTag', onpress: tag_action},
|
||||
{name: 'Rename', bclass: 'editTag', onpress: tag_action},
|
||||
{separator: true},
|
||||
{name: 'Help', bclass: 'help', onpress: bm_action}
|
||||
],
|
||||
searchitems : [
|
||||
{display: 'Full text (regexp)', name : ''},
|
||||
{display: 'Tags (comma seperated)', name : '_tags'},
|
||||
{display: 'Tags (regexp)', name : 'tags'},
|
||||
{display: 'Singel Folder', name : '_folder'},
|
||||
{display: 'Folders (regexp)', name : 'folders'},
|
||||
{display: 'Title (regexp)', name : 'title'},
|
||||
{display: 'Description (regexp)', name : 'desc'}
|
||||
],
|
||||
useRp: true,
|
||||
rp: 15,
|
||||
sortname: "title",
|
||||
sortorder: "asc",
|
||||
usepager: true,
|
||||
striped: true,
|
||||
nowrap: false,
|
||||
height: height,
|
||||
query: ".*",
|
||||
qtype: "title"
|
||||
});
|
||||
|
||||
/* Initialize Sidebar */
|
||||
$('#ymarks_sidebar').height(height+90);
|
||||
$tabs = $('#ymarks_sidebar').tabs({
|
||||
// tabs options
|
||||
});
|
||||
|
||||
$tabs.bind('tabsselect', function(event, ui) {
|
||||
/*
|
||||
Objects available in the function context:
|
||||
ui.tab - anchor element of the selected (clicked) tab
|
||||
ui.panel - element, that contains the selected/clicked tab contents
|
||||
ui.index - zero-based index of the selected (clicked) tab
|
||||
*/
|
||||
tabid = "#"+ui.panel.id;
|
||||
if (tabid == "#ymarks_tags_tab") {
|
||||
loadTagCloud();
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
$("#ymarks_treeview").treeview({
|
||||
url: "/api/ymarks/get_treeview.json?bmtype=href",
|
||||
unique: true,
|
||||
persist: "location"
|
||||
});
|
||||
|
||||
$("#ymarks_treeview").bind("click", function(event) {
|
||||
if ($(event.target).is("li") || $(event.target).parents("li").length) {
|
||||
var folder = $(event.target).parents("li").filter(":first").attr("id");
|
||||
$('#ymarks_flexigrid').flexOptions({
|
||||
query: folder,
|
||||
qtype: "_folder",
|
||||
newp: 1
|
||||
});
|
||||
$('#ymarks_flexigrid').flexReload();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
$("#example").multiselect();
|
||||
|
||||
});
|
||||
|
||||
function loadTagCloud() {
|
||||
$("#ymarks_tagcloud *").remove();
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/api/ymarks/get_tags.xml?top=25&sort=alpha",
|
||||
dataType: "xml",
|
||||
cache: false,
|
||||
success: function(xml) {
|
||||
$(xml).find('tag').each(function(){
|
||||
var count = $(this).attr('count');
|
||||
var tag = $(this).attr('tag');
|
||||
var size = ((count/20)+0.3);
|
||||
if (size < 1) {size = 1;}
|
||||
$('<a style="font-size:'+size+'em"></a>')
|
||||
.html(HTMLenc(tag)+' ')
|
||||
.appendTo('#ymarks_tagcloud')
|
||||
.bind('click', function() {
|
||||
var qtag = $(this).text().replace(/\s+$/g,"");
|
||||
$('#ymarks_flexigrid').flexOptions({
|
||||
query: qtag,
|
||||
qtype: "_tags",
|
||||
newp: 1
|
||||
});
|
||||
$('#ymarks_flexigrid').flexReload();
|
||||
});
|
||||
}); //close each(
|
||||
}
|
||||
}); //close $.ajax(
|
||||
};
|
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue