types,count,sparql , SPARQL: How do I List and count each data type in an RDF dataset?

SPARQL: How do I List and count each data type in an RDF dataset?


Tag: types,count,sparql

I am trying to count the instances of each datatype in a dataset. It is a simple dataset with only three data types: integer, string and dateTime.

I can get the number of datatypes (3) by querying:

AS ?dTypeCount) {?s ?p ?o. FILTER (isLiteral(?o)) } 
GROUP BY ?dTypeCount

result like so: -------------- | dTypeCount | ============== | 3 | --------------

I can get the listing of the datatypes (string, integer, dateTime) by querying:

SELECT DISTINCT (datatype(?o) AS ?dType) 
{?s ?p ?o. FILTER (isLiteral(?o)) } 

result like so:

| dType                                       |
| <http://www.w3.org/2001/XMLSchema#dateTime> |
| <http://www.w3.org/2001/XMLSchema#string>   |
| <http://www.w3.org/2001/XMLSchema#integer>  |

I can get a count of each datatype by querying:

SELECT (COUNT(?o) AS ?dTypeCount) 
{?s ?p ?o. FILTER (isLiteral(?o)) } 
GROUP BY datatype(?o)

result like so:

| dTypeCount |
| 23494      |
| 93548      |
| 228942     |

but I cannot get the name of the datatype displayed beside it's count i.e. looking something like so:

| dType                                       || dTypeCount |
| <http://www.w3.org/2001/XMLSchema#dateTime> || 23494      |
| <http://www.w3.org/2001/XMLSchema#string>   || 93548      |
| <http://www.w3.org/2001/XMLSchema#integer>  || 228942     |

I have tried various combinations of sub-queries, UNIONs, multiple GROUP BY bound variable and either do not get the desired result or get a "Non-group key variable in SELECT: " error. All help gratefully received.


Since you've grouped by the datatype of ?o, you know that all the ?o values in a group have the same datatype. You can just sample that to get one of those values, and then take the datatype of it:

select (datatype(sample(?o)) as ?datatype)
       (count(?o) AS ?dTypeCount)
where {
  ?s ?p ?o
  filter isLiteral(?o)
group by datatype(?o)

If you don't like having quite so many complex expressions around, you could bind the datatype within the query:

select ?datatype (count(?o) AS ?dTypeCount)
where {
  ?s ?p ?o
  filter isLiteral(?o)
  bind (datatype(?o) as ?datatype)
group by ?datatype


Efficiently finding the count of column values for distinct rows in a dataframe in r

Suppose I have a data frame as: id value 1 "hi" 1 "hi" 1 "hi again" 1 "hi again" 2 "hello" 2 "hi" Now I want to get the count of each value for each of the distinct values in id column. The output would be like id value Freq...

I need to find the longest word in a sentence using JS

I am having trouble getting my JS to return the longest word when I click on the button. I am not sure what in my JS code I am missing or have put incorrectly, but when I type in three words nothing is given back to me. I have pasted...

why (int) ( 307.03 * 100) = 30702 [duplicate]

This question already has an answer here: Is floating point math broken? 18 answers Today my coworker stumbled on this: $s = floatval("307.03"); $s = $s * 100; echo intval($s); //30702 float value or round($s) return 30703 as expected. I guess it's a problem connected with float to int...

Simple Table with dplyr on Sequence Data

I would like to make a simple table with dplyr and summarise But I can't really figure out how ... (Even though it should be quite simple). I have a matrix of sequences. When I simply tabulate table(dta) I have the result I want. dta acquaintance alone child notnotnot nuclear...

Should a HttpResponse's status_code attribute be an integer or a string?

When I am creating a HttpResponse object, should I pass it a integer for the status_code attribute, or a string? I.e. HttpResponse('401 Client Error', status=401) vs. HttpResponse('401 Client Error', status="401") The documentation is a generic descriptor, that doesn't give the type. HttpResponse.status_code The HTTP status code for the response. ...

MySQL count rows with same values

i have been searching but i didnt find what i was looking for. This is what i have: SELECT user_email, post_type FROM `wp_users` INNER JOIN `wp_posts` ON wp_users.id = wp_posts.post_author WHERE post_type LIKE '%topic%' OR post_type LIKE '%reply% it bring what i needed: I needed a query that shows me...

Mysql count and return just one row of data

I need to count the amount of users that have have answered all of those 3 profile_options (so they have at least 3 records in the profile_answers table). SELECT COUNT(DISTINCT(users.id)) users_count FROM users INNER JOIN profile_answers ON profile_answers.user_id = users.id WHERE profile_answers.profile_option_id IN (37,86,102) GROUP BY users.id HAVING COUNT(DISTINCT(profile_answers.id))>=3 The...

What's the equivalent of std::is_const for references to const?

Consider the code: int const x = 50; int const& y = x; cout << std::is_const<decltype(x)>::value << endl; // 1 cout << std::is_const<decltype(y)>::value << endl; // 0 This makes sense, because y is not a const reference, it is a reference to a const. Is there a foo such that...

C# - Get all types that been used in class A

how can I get all the types that been used in specific type? Example for class "MyClass": [MyAttribute(new OtherType(TestEnum.EnumValue1))] public class MyClass:MyOtherClass { public Type MyType { get; set; } public string MyString { get; set; } private DateTime MyDateTime; [OtherAttribute()] public int MyMethod(double doubleNumber, float floatNumber) { justMyClass myJustClass...

Select ID having maximum count of another ID

I have a database of baseball plays with a PlayerID and a TypeID (the kind of play: double, strike out, etc). The data looks something like this: +----------+--------+ | playerid | typeid | +----------+--------+ | 2 | 4 | | 2 | 4 | | 2 | 7 | |...

R — frequencies within a variable for repeating values

I've got a column A, which has several values, some of them repeating. So, example: A = c(5, 9, 6, 5, 5). I need to go through A and count the frequencies of each of the values in A. So, for this example, for the set of 5s in A,...

MySQL COUNT vs SELECT rows performance

I have a small table with three columns and using PHP. TABLE (id unsigned int(10), gameid unsigned int(10), userid unsigned int(10)) - id, gameid and userid are indexed. At some point (When a player join a game) system will check if the game already have 100 players in it, if...

Count multiple columns mysql

I am having hard time writing the query that counts occurrence of specific value in multiple columns. I cannot change the structure of db. I know I can do this using multiple queries and union at the end, but I was wondering is there any smarter solution. Here is an...

What are the most common bugs in OCaml/Haskell/Scala programs? [closed]

Now when we have these fancy type-systems to prevent null-pointer bugs and memory bugs and all, what common bugs are left? Can these bugs be prevented with different type-systems or further programming language research? Edit: Do we know what bugs are common in functional programming? Edit 2: -3 question with...

Counting word occurrences in a file C

Welcome everybody. I am new to Stackoverflow, I code in C for some time. I have run to a problem writing a program counting word occurrences in a text file. I need to have an output telling what word occurred how many times. Here is the source code: #include <stdio.h>...

SPARQL: How do I List and count each data type in an RDF dataset?

I am trying to count the instances of each datatype in a dataset. It is a simple dataset with only three data types: integer, string and dateTime. I can get the number of datatypes (3) by querying: SELECT (COUNT(DISTINCT datatype(?o)) AS ?dTypeCount) {?s ?p ?o. FILTER (isLiteral(?o)) } GROUP BY...

Best practice for handling data types from 3rd party libraries in Haskell?

I'm just getting into my first real Haskell project of size (a web app), and I'm starting to run into issues with types from 3rd party libraries leaking all over my code. Here is a quick example: My Parser module imports Test.Parsec, and the exports a function (parseConfig) that returns...

Count() function in mysql

my count function counts the records of the first table twice then add to that same result rather than add the count() of the two table records. How can I work around this? SELECT uln.user_id, count(uln.user_id)+count(uln.user_id) as user_pet_notif_count FROM user_legislation_notifications uln join user_petition_notifications upn on upn.user_id = uln.user_id where uln.user_id...

int* const* foo(int x); is a valid C function prototype. How do you “read” this return type?

I notice that this is a valid prototype while reading through the ANSI C grammar spec from 1985 published by Jeff Lee and I compiled a function with this signature. What exactly might a function with this prototype return? What would a simple body of this function look like?

MySql : issue with GROUP BY and COUNT clauses

I have this table I would like to display products(with their type) that have at least two different types. Here : I have tried this : SELECT PRODUCT, TYPE FROM MYTABLE group by PRODUCT, TYPE HAVING count(PRODUCT) > 1; but it doesn't give me the result I want....

Show All and Count Duplicates MySQL

I have this table: id name 1 AAA 2 BBB 3 BBB 4 BBB 5 AAA 6 CCC How can I get this? id name count 1 AAA 2 2 BBB 3 3 BBB 3 4 BBB 3 5 AAA 2 6 CCC 1 I want to count duplicates(name), getting...

SQL count date time

I have to concatenate the date and time portion of two fields, which I have managed to do, then I need to test if the result is < getdate() select count(cast(cast(DischargeDatenew as date) as datetime) + cast(DischargeTime as time))as Requiredby FROM [dbo].[Main] where Location = 'Home' and ScriptTypeID = '1'...

Create a type in sqlite

I was trying to make a basket of products and i need to create a type in sqlite like: create type B_productes as object ( id_product integer, quantity integer ); Or if you can give other solution.Thanks...

Haskell - Could not deduce … from Context error - OpenGL AsUniform class type

I'm working on making my data types general instead of taking in the OpenGL type GLfloat. So I started making it take in type a and then just replacing everything with that. Now, I've come to a point where I'm setting uniform variables, but they take in GLfloat's. I'm using...

How do I create a recursive typealias in julia?

I would like to create a nested tuple type, that can hold itself, or the particular type it contains. So I thought: typealias NestedTuple{T} Tuple{Union(T,NestedTuple{T}),Union(T,NestedTuple{T})} However this comes up with an error LoadError: UndefVarError: NestedTuple not defined How is this kind of typealias normally done? (I am in julia 0.4)...

Why does '12345'.count('') return 6 and not 5?

>>> '12345'.count('') 6 Why does this happen? If there are only 5 characters in that string, why is the count function returning one more? Also, is there a more effective way of counting characters in a string?...

Oracle COUNT() function

I have this query: select dates,To_char(dates,'DAY') DAYs FROM ( select trunc(ADD_MONTHS(sysdate,-1),'MM') + level -1 Dates from dual connect by level <= ADD_MONTHS(trunc(sysdate,'MM'),1)-1 - trunc(sysdate,'MM')+1 ) Where To_char(dates,'DY') NOT IN ('SA','SO') The output of query above is: 01.05.2015 FREITAG 04.05.2015 MONTAG 05.05.2015 DIENSTAG 06.05.2015 MITTWOCH 07.05.2015 DONNERSTAG 08.05.2015 FREITAG 11.05.2015 MONTAG...

Convert string built bit map (100101) to int value in SQL

Is it possible, and how would I go about converting a string representation of a bit mapping such as '10010' to cast it as the integer value it represents? We are using a string built bit map for permission settings, and I need to then cast it to the integer...

C code Count elements in array that are not null

going over old exam papers and doing questions, for this one: array is: char* s[]={"one","two",NULL,NULL,"five","",""}; using function name: int inUse(char *s[],int len) I have to determine the number of elements that are not NULL. I have come up with: int count=0; for(i=0; i<7, i++) { if(s !=NULL) { count ++;...

Excel - list entities (items)

Friends, I need to list all the unique entities (items) in a Excel spreadsheet, how to? E.g. **List1** 1 1 1.1 2 a a aa b c c And I need a certain function that returns: **Entities** 1 1.1 2 a aa b c Then I can count the occurence...

sql BIT to Java [closed]

My sqlserver table has a column designed as a BIT datatype. It has values 1 and 0s Then in my Java code, I do result = new ArrayList result.add( (Boolean)(rs.getBoolean("columnName"))); Then when I read the value from the list - it shows as Long. According to everything I find, it...

Return frequency of string in MYSQL column with PHP

after searching for several questions, i'm still struggling with mysql queries in PHP, my current goal is to do a MYSQL query that counts how many repeated strings are in a column and then return this amount in a INT variable to be written in the database. The current code...

shell script for counting replacements

Ten files located in a directory. Each file content has "apple" word. write a bash shell script to replace "apple" with "banana" in all ten files and Print the number of replacements for each file. Have tried in this way but dont know how to get number of replacement. can...

count cells quantity with a special contained word and calculate the percentage

How can I count cells quantity with a special contained word and calculate the percentage in excel? For example I have a survey database about a product. the feedbacks are "Good, Not Bad, Bad". I want to count the quantity of each type of feedbacks and finally calculate the percentages...

Javadoc: Do parameter and return need an explicit type description

When Javadoc'ing, I don't know whether you should explicitly say whether the parameters are of type String or int. For example /** * This method does something * @param foo an object of type Foo * @param abc the number of doors, of type int * @return the number of...

Count number of occurences in repeated variables (r)

I need to summarise the number of days that people have worked during a week. Each variables represent a day. I need to produce a summary of the number of days worked. I am not quite sure what would be a convenient manner to do it (beside summing the table...

Mysql nested count

I have 3 tables connected to each other booking > bid (booking_id) > bid_participants (bid_id) so when a booking is created, it will be blasted and received to more than 0 person or not received at all what i am trying to achieve is to count the booking if is...

Count unique values based on the newest element in a multidimentional array - PHP

Well basically, I have a multidimentional array that I want to count state, but sometimes in the array I can get duplicate lid, so I got to get the lid with the newest date_add [0] => Array ( [lhid] => 181 [lid] => 183 [uid] => 1 [state] => 2...

Unconstrained type parameters casting

My situation: interface ISomeInterface { void DoSmth<T>(T other); } class Base : ISomeInterface { public virtual void DoSmth<T>(T other){ // for example do nothing } } class Derived<T2> : Base { Action<T2> MyAction {get;set;} public override void DoSmth<T>(T other){ if(typeof(T2).IsAssignableFrom(typeof(T))) MyAction((T2) other); } } This gives me an error: Cannot...

Count from associate table

I want to have some stats from my app, User can publish post that I call Idee, and I want to know how many user have publish at least one idee. I'm assuming that should be something like: @total_user_active = User.where(idee.size >= 1).count But this doesn't work. It's user who...

“conflicting implementations for trait” when trying to be generic

Background: I'm using the nalgebra library and I want to create a structure that represents a multivariate normal distribution. M is the type of the matrix, e.g. Mat4<f64>. My current attempt looks like this: use std::ops::Mul; use std::marker::PhantomData; use nalgebra::*; #[allow(non_snake_case)] pub struct Multivar𝒩<N, V, M: SquareMat<N, V>> { μ:...

Regex/Algorithm to find 'n' repeated lines in a file

I am looking for an advanced version of this. Basically, if I have a file with text: abc ghi fed jkl abc ghi fed I want the output to be:(for n=3) Duplicated Lines abc ghi fed Times = 2 ...

Get column value on count (MySQL/Java)

I'm trying to get the number of times where a username has been found in a table, the thing is that I am just getting a value of "1" every time, even if the username is not found (where the value should be 0) I think the problem is that...

Why do c++ libraries often define their own primitive types?

I have started using OpenCL library lately and I've noticed that they are using their own integer types, like cl_int and cl_uint instead of int and unsigned int. Why is that? Why don't they use the types that are by default in the language? Is it a good practice or...

Why Comparison Of two Integer using == sometimes works and sometimes not? [duplicate]

This question already has an answer here: Why does 128==128 return false but 127==127 return true in this code? 4 answers Why equal operator works for Integer value until 128 number? [duplicate] 7 answers I know that i am comparing reference while i'm using == which is not a...

How can I express foldr in terms of foldMap for type-aligned sequences?

I'm playing around with type-aligned sequences, and in particular I'm messing around with the idea of folding them. A foldable type-aligned sequence looks something like this: class FoldableTA fm where foldMapTA :: Category h => (forall b c . a b c -> h b c) -> fm a b...

How can I express the type of 'takeWhile for vectors'?

Haskell beginner here. I've defined the following types: data Nat = Z | S Nat data Vector a n where Nil :: Vector a Z (:-) :: a -> Vector a n -> Vector a (S n) infixl 5 :- I'm trying to write the function, takeWhileVector which behaves the...

Java infinitely recursive self referential types

I'm trying to create an implementation of Map that takes collections as keys. What do you even call this conundrum? What is the right way to do the class signature? class SubClass <K extends Collection<E>, V> implements Map<K, V> ^^ Is improper syntax, but indicates what I want to do....

Count amount of inputfields with the same name in PHP?

I want to count the amount of inputfields with the name "termin"+number+"_von". So if there is one Inputfield with the name "termin1_von", a secound with the name "termin2_von" and third with the name "termin3_von" the code should print "123". cause there are 3 Inputs. What I want is that I...