DBpedia getting page category using sparql - r

I am using DBpedia to getting page category using SPARQL in R. However, there are having some problems on it. Source code I am using:
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?categoryUri ?categoryName WHERE {
<http://dbpedia.org/resource/xxx> dcterms:subject ?categoryUri.
## xxx are random words (e.g. Agree, Film, Work, Plan...)
?categoryUri rdfs:label ?categoryName.
FILTER (lang(?categoryName) = "en")
}
The problems are:
Category cannot be retrieved if the words need to be redirected (e.g. Agree -> Agreement)
Disambiguation pages cannot be used from the above source code, because there are so many sub-pages within the category of word (e.g. Work)
So, how can I resolve the above problems? I am really appreciate if anyone can offer your help!!!

SPARQL does only do what you write, so there is no magic behind. If some resource :s is possibly connected to others by a property :p, add a triple pattern :s :p ?o . - sometimes you might even consider to use a property path in case of the resolution of the transitive closure of :p, i.e. :s :p* ?o ..
With redirects resolved:
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dcterms: <http://purl.org/dc/terms/>
SELECT * WHERE
{ <http://dbpedia.org/resource/Agree> (dbo:wikiPageRedirects)* ?page
OPTIONAL
{ ?page dcterms:subject ?categoryUri}
}
Note the OPTIONAL clause, which is necessary here because not all resources in DBpedia belong to a category.
Including disambiguation pages:
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dcterms: <http://purl.org/dc/terms/>
SELECT * WHERE
{ <http://dbpedia.org/resource/Agree> (dbo:wikiPageRedirects)*/(dbo:wikiPageDisambiguates)* ?page
OPTIONAL
{ ?page dcterms:subject ?categoryUri}
}

Related

What is GRAPHDB_CONTEXT_TEST in Graphdb?

I am trying to set a new repository in GraphDB. The npm documentation say that
GRAPHDB_CONTEXT_TEST = 'http://ont.enapso.com/repo'; where is this "http://ont.enapso.com/repo" coming from?
Also, why do we need { prefix: 'entest', iri: 'http://ont.enapso.com/test#' } ?
In the test repository, it is:
But I don't understand if the inside the quotes is just a string, or a link?
GRAPHDB_CONTEXT_TEST = 'http://ont.enapso.com/repo';
This is the global variable in which we have 'http://ont.enapso.com/repo', which is to define which named graph would be used.
{ prefix: 'entest', iri: 'http://ont.enapso.com/test#' }
These are the prefixes that we could pass in along with their IRI. They are used to perform SPARQL queries which require your prefixes.
We pass the IRI inside the quotes referred to as an internationalized resource identifier. It is used to identify uniquely.
You can also check the updated documentation of the pack available at
ENAPSO GraphDB Client
ENAPSO GraphDB Admin
Hope that answers your questions.

tagging 'plain-language' vs technical definition in a SKOS vocabulary

I am trying to implement a technical glossary in SKOS (which uses BCP47) that has both a 'technical' scientific definition as well as a more accessible 'plain-language' definition. I have not been able to find an appropriate solution
Is there a best-practice for this ?
There is no specific level of technicality expressible through SKOS, but you may look into other vocabularies to find a property that would suit your needs, for example on Linked Open Vocabularies.
As for using such a property, I think the easiest would be to use rdf:CompoundLiteral to describe the literal itself:
<resource>
skos:prefLabel [
a rdf:CompoundLiteral ;
rdf:value "layman term" ;
rdf:language "en" ;
:isTechnical false
] ;
skos:altLabel [
a rdf:CompoundLiteral ;
rdf:value "technical term" ;
rdf:language "en" ;
:isTechnical true
] ;
Just remember that SKOS has an integrity condition such that only one skos:prefLabel may be present on a resource for a given language tag.
If you absolutely must use BCP47 (for language ranges, more restrictive formats etc.), I have tried to find a way to express what you want using existing standards and extensions, but I wasn't successful. In that case, the only remaining possibility is to use a private-use subtag, like "term"#en-x-tech.

Keyword Path in SDL Tridion

Could someone please give some idea on how this can be done? This might be very simple and basics, but i couldn't figure this out.
Here is my requirement.
I have a category A with child keyword B and B got another Child Keyword C.
I want to get the exact path of selected keyword in my component template,Say for eg, if user selects keyword C, i need the value with path like A\B\C and not just as C. But Tridion always gives me the value as C and not as A\B\C . Component Schema is using "Tree" view to select the keywords.
Should I be writing dreamweaver custom functions to handle this? Or does tridion comes with some handler for this?
Any help would be highly appreciated. Thank you!
Thanks,
KK
As you just found out, the Tridion Keyword Hierarchy is "fake" - Keywords are stored as a flat list, not as a hierarchical list (like you would have with folders). The information about the parent and children keywords is stored in the keyword itself.
There are solutions for this - of course, for instance you can use this in a C# TBB:
Keyword keyword = new Keyword(new TcmUri("tcm:28-3368-1024"), session);
string hierarchy = keyword.Title;
bool done = false;
while(!done)
{
if (keyword.ParentKeywords.Count > 0)
{
foreach (Keyword k in keyword.ParentKeywords)
{
hierarchy = k.Title + " > " + hierarchy;
}
keyword = keyword.ParentKeywords[0];
}
else
done = true;
}
// Include Category
hierarchy = keyword.OrganizationalItem.Title + " > " + hierarchy;
EDIT: Updated to recursively "go up" the hierarchy. HOWEVER a keyword can have multiple parents, I'll leave that up to you to fix...
Keywords within a category are unique, so Tridion can safely refer to them by their name (and/or their TCM URI of course). And since a Keyword can have multiple parents, there may not be a single path leading from the root to your Keyword.
If in your situation the category can be represented as a tree, you can of course build a single path to each keyword. In that case you'll need some (C#) code that walks up the parents axis and concatenates the names. You can put this code either:
in a TBB that you put into your template before the DWT OR
in a custom Dreamweaver function.
Either way will work fine.

How to check if a term exists with rules - Drupal 7

I had a previous question combining two questions on this subject...but I think I explained a little bit vague...too much story...so I will ask just one question at a time :)
I would like to know how I can check if a taxonomy term exists with Rules in Drupal 7.
I think I will need to do it with a custom PHP rule together with a native Drupal function (something like check_if_term_exists() ?).
But I cannot seem to find a correct way to do it.
Nice and easy:
$tid = 5; // The term ID, you can't load by term name as such because multiple terms may have the same name within different (and even within the same) vocabularies.
$term = taxonomy_term_load($tid);
if ($term) {
// The term exists
}
else {
// The term doesn't exist
}

How to change the label of the default value (-Any-) of an exposed filter in Drupal Views?

I created a view which has three exposed filters. Everything works fine except the fact that I can neither translate or change the default string (-Any-) for the dropdowns. Is there a way to change this string to something more meaningful like "Please Select" and make it translatable so the German version displays "Bitte wählen"? I have two screen captures that may be helpful:
and
A further improvement would be the ability to change the text "any" to something like "please select a (field name here)" but I am losing hope for that =)
UPDATE
IMPORTANT: On further testing, I found that if you choose to display "-Any-" from "admin/build/views/tools", then THAT IS translatable.
For anyone who wants to just change the value of "- Any -" to something in particular then use a custom module to override that looks like this:
function yourmodulename_form_alter(&$form, $form_state, $form_id) {
if($form_state['view']->name == 'your_view_name_here') {
$form['your_dropdown_name']['#options']['All'] = t('- Type -'); // overrides <All> on the dropdown
}
}
The reason you might want to do this is if you have 3 (for example) dropdowns for 3 separate fields. Then having on them wouldn't be very useful for a user (especially if you are not using labels).
In the code above just remember to change "yourmodulename" to the name of your module.
your_view_name_here should be the name of your view (replace dashes with underscores - for example "property-search-bar" would become "property_search_bar")
And change "your_dropdown_name" to the field name - I found this by using dsm($form) with the devel module installed and enabled. This is usually the field name of your drop down so it might be something like "field_my_custom_value".
Hope this helps anyone who needs it!
Three options:
You could change it with localisation, if you have that enabled already. Introducing localisation only for this string is far too much overhead.
You can change it with a form_alter, if you already alter the form anyway. Introducing a module with a hook_form alter for just one string is way too much (maintainance and performance) overhead.
You coud change it with a simple string override in your settings.php
In Drupal 7 (Drupal6 differs in details only)
/**
* String overrides:
*
* To override specific strings on your site with or without enabling locale
* module, add an entry to this list. This functionality allows you to change
* a small number of your site's default English language interface strings.
*
* Remove the leading hash signs to enable.
*/
$conf['locale_custom_strings_en'][''] = array(
'<Any>' => 'Whatever!',
);
Note though, that this will change every occurrance of the full string <Any> (case sensitive) to Whatever, not just the ones in that single form.
Views exposed filter label is not translatable in D6.
Go to Administer > Site building > Views and select tab tools.
Replace 'Label for "Any" value on optional single-select exposed filters: ' by the translatable '- Any -'.
Important: visit the views with exposed filters in at least one language which isn't your default language.
Then you can translate "- Any -" through Aminister > Site building > Translate interface (case sensitive).
Or you can simply use a line of jQuery code like this:
$(document).ready(function(){
$("#views-exposed-form-url-name-display-name #edit-tid-all a").text("All");
});
The Better Exposed Filter module allows you to change the "-any-" label in a Views exposed filter.
I'd rather go with the simple solution: String Overrides.
With this you simply add a string you want to change on your site, and replace it with anything you want (Strings of course).
May be module https://www.drupal.org/project/views_advanced_labels helps?
I found it, but have not tried it yet.
if ($form['#id'] == 'views-exposed-form-project-search-block-project-search') {
foreach ($form['#info'] as $filter_info) {
$filter = $filter_info['value'];
if ($form[$filter]['#type'] == 'select') {
$form[$filter]['#options']['All'] = $filter_info['label'];
}
}
}
If you use Better Exposed Filters module, go into Exposed Form > Exposed form style: Better Exposed Filters | Settings > look for your field > Advanced Filter Options > put "- Any -|All" in the "Rewrite the text displayed" field.

Resources