0

below is my query code.. I am trying to put together several types to get one query to build a set of data off of...but the query does not work from php, it does work inside of query editor on freebase.com

    <?php

function getQuery($type,$id=null){
    //leaves off closing so you can return and append to the end of everything following...
    $query = "[{
        \"type\":\"$type\",
        \"limit\":10,
        \"id\":null,
        \"name\":null,";

    return $query;
}

function getSportsTeamsStructure(){

    $query = "\"/sports/sports_team/sport\":null,";
    $query .="\"/sports/sports_team/league\":[{\"team\":null,\"league\":null,\"from\":null,\"to\":null}],";
    $query .="\"/sports/sports_team/location\":[{".getLocationStructure()."}],";
    $query .="\"/sports/sports_team/founded\":null,";
    $query .="\"/sports/sports_team/arena_stadium\":[{".getArchitectureStructure()."}],";
    $query .="\"/sports/sports_team/colors\":[{}],";
    $query .="\"/sports/sports_team/team_mascot\":[{}],";
    $query .="\"/sports/sports_team/championships\":[{}],";
    $query .="\"/sports/sports_team/fight_song\":[{}],";
    $query .="\"/sports/sports_team/roster\":[{\"position\":[{}],\"team\":[{}],\"number\":[],\"from\":null,\"to\":null}],";
    $query .="\"/sports/sports_team/coaches\":[{\"position\":[{}],\"from\":null,\"to\":null,\"team\":[{}],\"coach\":[{}]}]";
    return $query;
}
function getPeoplePersonStructure(){
    $query = '';
    $query .= "\"/people/person/date_of_birth\":null,";
    $query .="\"/people/person/place_of_birth\":null,";
    $query .="\"/people/person/nationality\":null,";
    $query .="\"/people/person/gender\":null,";
    $query .="\"/people/person/profession\":[{}],";
    $query .="\"/people/person/religion\":[{}],";
    $query .="\"/people/person/ethnicity\":[{}],";
    $query .="\"/people/person/parents\":[{}],";
    $query .="\"/people/person/children\":[{}],";
    $query .="\"/people/person/sibling_s\":[{}],";
    $query .="\"/people/person/spouse_s\":[{}],";
    $query .="\"/people/person/height_meters\":null,";
    $query .="\"/people/person/weight_kg\":null,";
    $query .="\"/people/person/education\":[{}],";
    $query .="\"/people/person/age\":[{}],";
    $query .="\"/people/person/notable_professions\":[{}],";
    $query .="\"/people/person/languages\":[{}]";

    return $query;

}
function getCommonTopicStructure(){

    $query = '';
    $query .="\"/common/topic/image\":[{}],";
    $query .="\"/common/topic/article\":[{}],";
    $query .="\"/common/topic/notable_for\":[],";
    $query .="\"/common/topic/notable_types\":[],";
    $query .="\"/common/topic/alias\":[],";
    $query .="\"/common/topic/description\":[],";
    $query .="\"/common/topic/official_website\":[],";
    $query .="\"/common/topic/topic_equivalent_webpage\":[],";
    $query .="\"/common/topic/subjects\":[],";
    $query .="\"/common/topic/subject_of\":[],";
    $query .="\"/common/topic/weblink\":[],";
    $query .="\"/common/topic/social_media_presence\":[{}]";
    return $query;
}
function getArchitectureStructure(){
    $query = '';
    $query = "\"/architecture/structure/architect\":[{".getPeoplePersonStructure()."}],";
    $query = "\"/architecture/structure/architectural_style\":[],";
    $query .="\"/architecture/structure/owner\":[{}],";
    $query .="\"/architecture/structure/architecture_firm\":[{}],";
    $query .="\"/architecture/structure/height_meters\":null,";
    $query .="\"/architecture/structure/construction_cost\":null,";
    $query .="\"/architecture/structure/destruction_date\":null,";
    $query .="\"/architecture/structure/destroyed_by\":null,";
    $query = "\"/architecture/structure/address\":[{".getMailingAddressStructure()."}],";
    $query .="\"/architecture/venue/capacity\":null";

    return $query;

}
function getLocationStructure(){
    $query = '';
    $query .= "\"/location/location/geolocation\":[{\"id\":null,\"longitude\":null,\"latitude\":null,\"daturn\":null,\"elevation\":null}],";
    $query .= "\"/location/location/contains\":[{}],";
    $query .="\"/location/location/containedby\":[{}],";
    $query .="\"/location/location/adjoin_s\":[{}],";
    $query .= "\"/location/location/area\":null,";
    $query .="\"/location/location/time_zones\":[{}],";
    $query .= "\"/location/location/people_born_here\":[{}],";
    $query .= "\"/location/location/events\":[{}],";
    $query .="\"/location/location/nearby_airports\":[{}],";
    $query .="\"/location/location/near\":[{}],";
    $query .="\"/location/location/street_address\":{{".getMailingAddressStructure()."}],";
    return $query;

}
function getMailingAddressStructure(){
    $query = '';
    $query = "\"street_address\":null,\"street_address_2\":null,\"citytown\":null,\"state_province_region\":null,\"postal_code\":null,\"country\":null";
    return $query;

}
?>
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
Andrew
  • 136
  • 2
  • 11
  • I don't have time to debug your code for you, but one thing you should be aware of is that the query edit silently fixes up queries, so check for things like missing commas, etc. Also, the asymmetric "leave off the final ]" is going to be very bug prone. If it's not the problem now, it will be in the future. – Tom Morris May 14 '13 at 21:31
  • Hey Tom...I picked up on the editor fixing the queries...I think it boils down to the length of the final url...I think that may be my major issue.. I could be wrong... be at this all day trying to figure out a way to build these queries up – Andrew May 14 '13 at 22:44
  • The query editor has a "Link" button which will give you an MQLread URL that you can use directly. If that works and your code doesn't the problem isn't the length. – Tom Morris May 15 '13 at 13:33

0 Answers0