Showing posts with label query. Show all posts
Showing posts with label query. Show all posts

# How to query SPARQL with spaces?

 RDF itself uses RDF URI references. The SPARQL query language, on the other hand, uses IRIs (the reason is that RDF predates IRIs and the notion of RDF URI references was developed in anticipation of what IRIs were expected to eventually look like. They almost got it right :)).


RDF URI references allow whitespaces while IRIs do not. 

Another way of doing this is by using FILTER (STR(?Y)) "your url") like below:


PREFIX owl:  

SELECT ?y 

WHERE { 

   ?y owl:sameAs ?x

   FILTER (str(?x) = "http://website.com/urls/playing fun")

}

[1]. http://stackoverflow.com/questions/9055146/querying-with-spaces-sparql

SQL 자주 쓰는 쿼리

  • Table RandomSample20ForEachPR에서 TUIMSimPrecision이라는 Column 삭제 
 ALTER TABLE aboutme.RandomSample20ForEachPR DROP COLUMN TUIMSimPrecision  
  • Table RandomSample의 TopicCount라는 Column을 TestFlag로 이름 변경
 ALTER TABLE aboutme.RandomSample CHANGE TopicCount TestFlag INT  
  • Table RandomSample20ForEach의 MUIMSim이라는 Column의 데이터속성 변경 
 ALTER TABLE aboutme.RandomSample20ForEach MODIFY COLUMN MUIMSim decimal(12,10)  
  • SUM() and LIMIT  같이 쓸때
 SELECT SUM(SampleFlag) FROM   
      (SELECT SampleFlag FROM aboutme.RandomSample20ForEach WHERE TwitterURI = 'http://www.twitter.com/parklize' ORDER BY TUIMSim DESC LIMIT 10)   
      AS SuccessRate  

  • INSERT INTO... SELECT FROM
 INSERT INTO table2  
 (column_name(s))  
 SELECT column_name(s)  
 FROM table1;  
  • Subquery  limit 문구넣고 실행
 INSERT INTO aboutme.RandomSample50 (TwitterURI, LINK, TopicCount, CreateTime, TestFlag)   
 SELECT TwitterURI, LINK, TopicCount, CreateTime, 1 FROM aboutme.RandomSample  
 WHERE PositiveTestCases = '1' AND TwitterURI IN  
 (SELECT * FROM (SELECT DISTINCT TwitterURI FROM aboutme.RandomSample ORDER BY RAND() LIMIT 50) temp);  
  • Substring
SELECT SUBSTRING_INDEX(UGCID2, '/', -1) FROM UGCListFor150URL  
http://www.twitter.com/parklize/status/562289797117800448->562289797117800448
  • MAMP 에서 MySQL접속 및 sql 파일 실행하기
 
/Applications/MAMP/Library/bin/mysql --host=localhost -uroot -proot  

MySql접속후 아래 명령으로 .sql파일 실행시킨다.

 mysql> source file_name  
 mysql> \. file_name  

  • 현재 connection수 확인하고 kill하기
 SHOW STATUS WHERE `variable_name` = 'Threads_connected';  
 SHOW PROCESSLIST;  
 KILL 9690; // use id to kill the process  

  • Get all "KILL" command for ending all processes over 200 secs.

 select concat('KILL ',id,';') from information_schema.processlist  
 where user='root' and time > 200;  


  • update from select
 update RandomSampleUIM uim, (select distinct Topic, BabelID from _RandomSampleUIM) olduim set uim.`BabelID` = olduim.`BabelID` where uim.`Topic` = olduim.`Topic`;  


  • my.conf 설정 (/etc/mysql/my.conf)
    • max_connections: 연결가능한 connections 수를 설정
  • Ubuntu MySQL start/stop
    • /etc/init.d/mysql start/stop/restart

Semantic Web Practice - Other SPARQL Query Forms (CONSTRUCT, ASK, DESCRIBE)

In SPARQL, there are four query forms - SELECT, CONSTRUCT, ASK, DESCRIBE with different return values.
  • SELECT : Return all or subset of the variables bound in a query pattern match
  • CONSTRUCT : Returns an RDF graph constructed by substituting variables in a set of triple templates.
  • ASK : Returns a Boolean indicating whether a query pattern matches or not.
  • Describe : Returns an RDF graph that describes the resources found.

Since we all quite know well about SELECT form, I'd like to give example on other forms here. Suppose we have ontology as below and four books have their prices separately.

Practice#1 : Get books(Subject)→price(Predicate)→price value(Object) triples.

1:  PREFIX : <http://boobks.example#>  
2:  CONSTRUCT { ?book :price ?price }  
3:  WHERE {  
4:   ?book :price ?price .  
5:  }  
6:  ORDER BY ?book  

Query Result : 






Practice#2 : Use ASK form to test Subject→affiliates(Predicate)→Object pattern exist or not.

1:  PREFIX : <http://boobks.example#>  
2:  ASK { ?org :affiliates ?author}  

Practice#3 : Get RDF graph  describes Subject→writesBook(Predicate)→book3(Object).


1:  PREFIX : <http://boobks.example#>  
2:  DESCRIBE ?x  
3:  WHERE { ?x :writesBook :book3 }  

Query Result : It will return RDF graph describe your query pattern.