How to use distance method in differencify

Best JavaScript code snippet using differencify

build_attribute_graph_from_wpt_without_distances.js

Source:build_attribute_graph_from_wpt_without_distances.js Github

copy

Full Screen

1/*2{3 common_name: [<concept>,...],4 descriptions: [{text:<text>, source_name:<source>, source_URL:<URL>, source_updated_at:<date or null>}, ...]5 edges: {6 <connected concept>: {7 descriptors: [8 {relationship_category:<category>, relationship_subcategory:<subcategory>, snippet:<custom snippet or empty string>, source_name:<source_name>, source_URL:<URL>, distance:<distance>, added_at:<date>, updated_at:<date>, source_updated_at:<date or null>},9 ...10 ],11 distance: <minimum of above distances>,12 added_at: <date>,13 updated_at: <date>14 },15 ...16 },17 prominence: <distance (based on number of inlinks or such)>,18 aliases: [ <alias>, .... ],19 web_sites: {crunchbase: <URL>, home_page:<URL>, twitter: <URL>, ...},20 locations: [{latitude: <latitude>, longitude: <longitude>, ...],21 added_at: <date>,22 last_updates: {<source_name>:<date>, ...}23} 24 */25var ATTRIBUTE_RULES = {26 "infobox actor": {27 "occupation": {28 "reverse_distance": 60,29 "subcategory": "OCCUPATION",30 "category": "PERSON",31 "template": "[[T]] worked as a [[X]]",32 "distance": 2033 },34 "domestic_partner": {35 "reverse_distance": 10,36 "subcategory": "PARTNER",37 "category": "GENEOLOGICAL",38 "template": "[[T]] lives with [[X]]",39 "distance": 1040 },41 "birthplace": {42 "reverse_distance": 70,43 "subcategory": "BIRTH",44 "category": "PERSON",45 "template": "[[T]] was born in [[X]]",46 "distance": 2047 },48 "spouse": {49 "reverse_distance": 10,50 "subcategory": "SPOUSE",51 "category": "GENEOLOGICAL",52 "template": "[[T]] and [[X]] are married",53 "distance": 1054 }55 },56 "infobox film": {57 "studio": {58 "reverse_distance": 30,59 "subcategory": "LOCATION",60 "category": "FILM",61 "template": "[[T]] was filmed in [[X]]",62 "distance": 1063 },64 "writer": {65 "reverse_distance": 10,66 "subcategory": "WRITER",67 "category": "FILM",68 "template": "[[X]] wrote [[T]]",69 "distance": 1070 },71 "director": {72 "reverse_distance": 10,73 "subcategory": "DIRECTOR",74 "category": "FILM",75 "template": "[[X]] directed [[T]]",76 "distance": 1077 },78 "editing": {79 "reverse_distance": 10,80 "subcategory": "EDITOR",81 "category": "FILM",82 "template": "[[X]] edited [[T]]",83 "distance": 1084 },85 "cinematography": {86 "reverse_distance": 10,87 "subcategory": "CINEMATOGRAPHER",88 "category": "FILM",89 "template": "[[X]] did the cinematography for [[T]]",90 "distance": 1091 },92 "music": {93 "reverse_distance": 10,94 "subcategory": "COMPOSER",95 "category": "FILM",96 "template": "[[X]] composed the music for [[T]]",97 "distance": 1098 },99 "starring": {100 "reverse_distance": 10,101 "subcategory": "STAR",102 "category": "FILM",103 "template": "[[X]] appeared in [[T]]",104 "distance": 10105 },106 "distributor": {107 "reverse_distance": 30,108 "subcategory": "DISTRIBUTOR",109 "category": "FILM",110 "template": "[[T]] was distributed by [[X]]",111 "distance": 30112 },113 "producer": {114 "reverse_distance": 10,115 "subcategory": "PRODUCER",116 "category": "FILM",117 "template": "[[X]] produced [[T]]",118 "distance": 10119 }120 },121 "infobox single": {122 "artist": {123 "reverse_distance": 10,124 "subcategory": "ARTIST",125 "category": "MUSIC",126 "template": "[[T]] is a single by [[X]]",127 "distance": 10128 },129 "writer": {130 "reverse_distance": 10,131 "subcategory": "LYRICIST",132 "category": "MUSIC",133 "template": "[[X]] wrote [[T]]",134 "distance": 30135 },136 "format": {137 "reverse_distance": 60,138 "subcategory": "FORMAT",139 "category": "MUSIC",140 "template": "[[T]] was released in [[X]] format",141 "distance": 30142 },143 "genre": {144 "reverse_distance": 70,145 "subcategory": "GENRE",146 "category": "MUSIC",147 "template": "[[T]] is in the genre of [[X]]",148 "distance": 20149 },150 "from album": {151 "reverse_distance": 10,152 "subcategory": "ALBUM",153 "category": "MUSIC",154 "template": "[[T]] is a single from the album [[X]]",155 "distance": 10156 },157 "label": {158 "reverse_distance": 50,159 "subcategory": "LABEL",160 "category": "MUSIC",161 "template": "[[T]] was released by [[X]]",162 "distance": 30163 }164 },165 "infobox broadcast": {166 "city": {167 "reverse_distance": 60,168 "subcategory": "LOCATION",169 "category": "BROADCAST MEDIA",170 "template": "[[T]] broadcasts in [[X]]",171 "distance": 50172 },173 "affiliations": {174 "reverse_distance": 50,175 "subcategory": "AFFILIATION",176 "category": "BROADCAST MEDIA",177 "template": "[[T]] is affiliated with [[X]]",178 "distance": 30179 },180 "licensee": {181 "reverse_distance": 40,182 "category": "BROADCAST MEDIA",183 "template": "[[X]] licenses [[T]]",184 "distance": 30185 },186 "sister_stations": {187 "reverse_distance": 40,188 "subcategory": "AFFILIATION",189 "category": "BROADCAST MEDIA",190 "template": "[[T]] is a twin station of [[X]]",191 "distance": 40192 },193 "owner": {194 "reverse_distance": 40,195 "subcategory": "INVESTMENT",196 "category": "BUSINESS",197 "template": "[[X]] owns [[T]]",198 "distance": 10199 },200 "former_affiliations": {201 "reverse_distance": 30,202 "subcategory": "AFFILIATION",203 "category": "BROADCAST MEDIA",204 "template": "[[X]] was affiliated with [[T]]",205 "distance": 30206 },207 "location": {208 "reverse_distance": 60,209 "subcategory": "LOCATION",210 "category": "BROADCAST MEDIA",211 "template": "[[T]]'s studio is located in [[X]]",212 "distance": 50213 }214 },215 "infobox website": {216 "author": {217 "reverse_distance": 10,218 "subcategory": "CREATOR",219 "category": "WEB",220 "template": "[[X]] created [[T]]",221 "distance": 10222 },223 "owner": {224 "reverse_distance": 30,225 "subcategory": "INVESTMENT",226 "category": "BUSINESS",227 "template": "[[X]] operates [[T]]",228 "distance": 30229 }230 },231 "infobox software": {232 "author": {233 "reverse_distance": 25,234 "subcategory": "DEVELOPER",235 "category": "TECHNOLOGY",236 "template": "[[X]] wrote [[y]]",237 "distance": 10238 },239 "developer": {240 "reverse_distance": 25,241 "subcategory": "DEVELOPER",242 "category": "TECHNOLOGY",243 "template": "[[X]] developed [[T]]",244 "distance": 10245 }246 },247 "infobox television": {248 "director": {249 "reverse_distance": 10,250 "subcategory": "DIRECTOR",251 "category": "BROADCAST MEDIA",252 "template": "[[T]] was directed by [[X]]",253 "distance": 10254 },255 "writer": {256 "reverse_distance": 10,257 "subcategory": "WRITER",258 "category": "BROADCAST MEDIA",259 "template": "[[T]] was written by [[X]]",260 "distance": 10261 },262 "creator": {263 "reverse_distance": 10,264 "subcategory": "CREATOR",265 "category": "BROADCAST MEDIA",266 "template": "[[T]] was created by [[X]]",267 "distance": 10268 },269 "opentheme": {270 "reverse_distance": 10,271 "subcategory": "MUSIC",272 "category": "BROADCAST MEDIA",273 "template": "[[T]]'s opening theme was [[X]]",274 "distance": 10275 },276 "narrated": {277 "reverse_distance": 10,278 "subcategory": "VOICE",279 "category": "BROADCAST MEDIA",280 "template": "[[T]] was narrated by [[X]]",281 "distance": 10282 },283 "voices": {284 "reverse_distance": 20,285 "subcategory": "VOICE",286 "category": "BROADCAST MEDIA",287 "template": "[[X]] was a voice on [[T]]",288 "distance": 20289 },290 "starring": {291 "reverse_distance": 10,292 "subcategory": "STAR",293 "category": "BROADCAST MEDIA",294 "template": "[[T]] starred [[X]]",295 "distance": 10296 },297 "endtheme": {298 "reverse_distance": 10,299 "subcategory": "MUSIC",300 "category": "BROADCAST MEDIA",301 "template": "[[T]]'s ending theme was [[X]]",302 "distance": 10303 },304 "channel": {305 "reverse_distance": 70,306 "subcategory": "CHANNEL",307 "category": "BROADCAST MEDIA",308 "template": "[[T]] was shown on [[X]]",309 "distance": 30310 },311 "genre": {312 "reverse_distance": 60,313 "subcategory": "GENRE",314 "category": "BROADCAST MEDIA",315 "template": "[[T]] belongs to the genre [[X]]",316 "distance": 20317 },318 "theme_music_composer": {319 "reverse_distance": 20,320 "subcategory": "MUSICIAN",321 "category": "BROADCAST MEDIA",322 "template": "[[T]]'s theme music was composed by [[X]]",323 "distance": 20324 },325 "location": {326 "reverse_distance": 70,327 "subcategory": "LOCATION",328 "category": "BROADCAST MEDIA",329 "template": "[[T]] was shot in [[X]]",330 "distance": 40331 },332 "judges": {333 "reverse_distance": 20,334 "subcategory": "STAR",335 "category": "BROADCAST MEDIA",336 "template": "[[X]] was a judge on [[T]]",337 "distance": 20338 }339 },340 "infobox newspaper": {341 "newseditor": {342 "reverse_distance": 10,343 "subcategory": "EDITOR",344 "category": "PRINT MEDIA",345 "template": "[[X]] is the news editor of [[T]]",346 "distance": 10347 },348 "chiefeditor": {349 "reverse_distance": 10,350 "subcategory": "EDITOR",351 "category": "PRINT MEDIA",352 "template": "[[X]] is the chief editor of [[T]]",353 "distance": 10354 },355 "sportseditor": {356 "reverse_distance": 10,357 "subcategory": "EDITOR",358 "category": "PRINT MEDIA",359 "template": "[[X]] is the sports editor of [[T]]",360 "distance": 10361 },362 "campuseditor": {363 "reverse_distance": 10,364 "subcategory": "EDITOR",365 "category": "PRINT MEDIA",366 "template": "[[X]] is the campus editor of [[T]]",367 "distance": 10368 },369 "photoeditor": {370 "reverse_distance": 10,371 "subcategory": "EDITOR",372 "category": "PRINT MEDIA",373 "template": "[[X]] is the photo editor of [[T]]",374 "distance": 10375 },376 "assoceditor": {377 "reverse_distance": 10,378 "subcategory": "EDITOR",379 "category": "PRINT MEDIA",380 "template": "[[X]] is the associate editor of [[T]]",381 "distance": 10382 },383 "sister newspapers": {384 "reverse_distance": 40,385 "subcategory": "RELATED",386 "category": "PRINT MEDIA",387 "template": "[[T]] and [[X]] are sister newspapers",388 "distance": 40389 },390 "staff": {391 "reverse_distance": 10,392 "subcategory": "WRITER",393 "category": "PRINT MEDIA",394 "template": "[[X]] is a writer at [[T]]",395 "distance": 10396 },397 "founder": {398 "reverse_distance": 10,399 "subcategory": "EMPLOYEE",400 "category": "BUSINESS",401 "template": "[[X]] founded [[T]]",402 "distance": 10403 },404 "campuschief": {405 "reverse_distance": 10,406 "subcategory": "EDITOR",407 "category": "PRINT MEDIA",408 "template": "[[X]] is the campus chief of [[T]]",409 "distance": 10410 },411 "managingeditordesign": {412 "reverse_distance": 10,413 "subcategory": "EDITOR",414 "category": "PRINT MEDIA",415 "template": "[[X]] is the managing design editor of [[T]]",416 "distance": 10417 },418 "editor": {419 "reverse_distance": 10,420 "subcategory": "EDITOR",421 "category": "PRINT MEDIA",422 "template": "[[X]] is the editor of [[T]]",423 "distance": 10424 },425 "publisher": {426 "reverse_distance": 10,427 "subcategory": "PUBLISHER",428 "category": "PRINT MEDIA",429 "template": "[[X]] is the publisher of [[T]]",430 "distance": 10431 },432 "opeditor": {433 "reverse_distance": 10,434 "subcategory": "EDITOR",435 "category": "PRINT MEDIA",436 "template": "[[X]] is the opinion editor of [[T]]",437 "distance": 10438 },439 "maneditor": {440 "reverse_distance": 10,441 "subcategory": "EDITOR",442 "category": "PRINT MEDIA",443 "template": "[[X]] is the managing editor of [[T]]",444 "distance": 10445 },446 "headquarters": {447 "reverse_distance": 50,448 "subcategory": "LOCATION",449 "category": "BUSINESS",450 "template": "[[T]]'s headquarters is in [[X]]",451 "distance": 50452 },453 "owner": {454 "reverse_distance": 20,455 "subcategory": "INVESTMENT",456 "category": "BUSINESS",457 "template": "[[X]] owns [[T]]",458 "distance": 20459 }460 },461 "infobox musical artist": {462 "occupation": {463 "reverse_distance": 70,464 "subcategory": "OCCUPATION",465 "category": "PERSON",466 "template": "[[T]] worked as a [[X]]",467 "distance": 30468 },469 "instrument": {470 "reverse_distance": 50,471 "subcategory": "PERSONAL_INSTRUMENT",472 "category": "MUSIC",473 "template": "[[T]] makes music with their [[X]]",474 "distance": 10475 },476 "past_members": {477 "reverse_distance": 10,478 "subcategory": "BAND_MEMBER",479 "category": "MUSIC",480 "template": "[[X]] was a member of [[T]]",481 "distance": 10482 },483 "notable_instruments": {484 "reverse_distance": 60,485 "subcategory": "PERSONAL_INSTRUMENT",486 "category": "MUSIC",487 "template": "[[T]] makes music with their [[X]]",488 "distance": 20489 },490 "associated_acts": {491 "reverse_distance": 50,492 "subcategory": "COLLABORATOR",493 "category": "MUSIC",494 "template": "[[T]] collaborated with [[X]]",495 "distance": 50496 },497 "origin": {498 "reverse_distance": 60,499 "subcategory": "BIRTH",500 "category": "PERSON",501 "template": "[[T]] was born in [[X]]",502 "distance": 10503 },504 "genre": {505 "reverse_distance": 60,506 "subcategory": "GENRE",507 "category": "MUSIC",508 "template": "[[T]]'s music belongs to the genre [[X]]",509 "distance": 30510 },511 "current_members": {512 "reverse_distance": 10,513 "subcategory": "BAND_MEMBER",514 "category": "MUSIC",515 "template": "[[X]] is a member of [[T]]",516 "distance": 10517 },518 "label": {519 "reverse_distance": 30,520 "subcategory": "LABEL",521 "category": "MUSIC",522 "template": "[[T]] was signed by [[X]]",523 "distance": 20524 },525 "spouse": {526 "reverse_distance": 10,527 "subcategory": "SPOUSE",528 "category": "GENEALOGICAL",529 "template": "[[T]] and [[X]] are married",530 "distance": 10531 }532 },533 "infobox television episode": {534 "director": {535 "reverse_distance": 20,536 "subcategory": "DIRECTOR",537 "category": "BROADCAST MEDIA",538 "template": "[[X]] directed [[T]]",539 "distance": 10540 },541 "writer": {542 "reverse_distance": 10,543 "subcategory": "WRITER",544 "category": "BROADCAST MEDIA",545 "template": "[[X]] wrote [[T]]",546 "distance": 10547 },548 "music": {549 "reverse_distance": 20,550 "subcategory": "MUSICIAN",551 "category": "BROADCAST MEDIA",552 "template": "[[X]] wrote the music for [[T]]",553 "distance": 20554 },555 "series": {556 "reverse_distance": 10,557 "subcategory": "SERIES",558 "category": "BROADCAST MEDIA",559 "template": "[[T]] was an episode of [[X]]",560 "distance": 10561 },562 "editor": {563 "reverse_distance": 10,564 "subcategory": "EDITOR",565 "category": "BROADCAST MEDIA",566 "template": "[[X]] edited [[T]]",567 "distance": 20568 },569 "producer": {570 "reverse_distance": 40,571 "subcategory": "PRODUCER",572 "category": "BROADCAST MEDIA",573 "template": "[[X]] produced [[T]]",574 "distance": 40575 },576 "photographer": {577 "reverse_distance": 10,578 "subcategory": "CREW",579 "category": "BROADCAST MEDIA",580 "template": "[[X]] was the director of photography for [[T]]",581 "distance": 30582 },583 "guests": {584 "reverse_distance": 50,585 "subcategory": "ACTOR",586 "category": "BROADCAST MEDIA",587 "template": "[[X]] made a guest appearance on [[T]]",588 "distance": 50589 }590 },591 "infobox magazine": {592 "company": {593 "reverse_distance": 40,594 "subcategory": "PUBLISHER",595 "category": "PRINT MEDIA",596 "template": "[[X]] publishes [[T]]",597 "distance": 40598 },599 "staff_writer": {600 "reverse_distance": 50,601 "subcategory": "WRITER",602 "category": "PRINT MEDIA",603 "template": "[[X]] writes for [[T]]",604 "distance": 20605 },606 "based": {607 "reverse_distance": 70,608 "subcategory": "LOCATION",609 "category": "PRINT MEDIA",610 "template": "[[T]] is based in [[X]]",611 "distance": 50612 },613 "previous_editor": {614 "reverse_distance": 10,615 "subcategory": "EDITOR",616 "category": "PRINT MEDIA",617 "template": "[[X]] was the editor of [[T]]",618 "distance": 10619 },620 "publisher": {621 "reverse_distance": 40,622 "subcategory": "PUBLISHER",623 "category": "PRINT MEDIA",624 "template": "[[T]] publishes [[X]]",625 "distance": 40626 },627 "editor": {628 "reverse_distance": 10,629 "subcategory": "EDITOR",630 "category": "PRINT MEDIA",631 "template": "[[X]] is the editor of [[T]]",632 "distance": 10633 }634 },635 "infobox book": {636 "author": {637 "reverse_distance": 10,638 "subcategory": "AUTHOR",639 "category": "LITERATURE",640 "template": "[[X]] wrote [[T]]",641 "distance": 10642 },643 "genre": {644 "reverse_distance": 60,645 "subcategory": "GENRE",646 "category": "LITERATURE",647 "template": "[[T]] belongs to the genre [[X]]",648 "distance": 50649 }650 },651 "infobox album": {652 "artist": {653 "reverse_distance": 10,654 "subcategory": "ARTIST",655 "category": "MUSIC",656 "template": "[[X]] recorded [[T]]",657 "distance": 10658 },659 "next album": {660 "reverse_distance": 40,661 "subcategory": "RELATED_ALBUM",662 "category": "MUSIC",663 "template": "[[X]] was the group's next album after [[T]]",664 "distance": 40665 },666 "last album": {667 "reverse_distance": 40,668 "subcategory": "RELATED_ALBUM",669 "category": "MUSIC",670 "template": "[[X]] was the group's last album before [[T]]",671 "distance": 40672 },673 "recorded": {674 "reverse_distance": 60,675 "subcategory": "RECORDING_YEAR",676 "category": "MUSIC",677 "template": "[[T]] was recorded during [[X]]",678 "distance": 20679 },680 "producer": {681 "reverse_distance": 50,682 "subcategory": "PRODUCER",683 "category": "MUSIC",684 "template": "[[X]] produced [[T]]",685 "distance": 40686 },687 "genre": {688 "reverse_distance": 70,689 "subcategory": "GENRE",690 "category": "MUSIC",691 "template": "[[T]] belongs to the genre [[X]]",692 "distance": 30693 },694 "released": {695 "reverse_distance": 60,696 "subcategory": "RELEASE_DATE",697 "category": "MUSIC",698 "template": "[[T]] was released on [[X]]",699 "distance": 20700 },701 "label": {702 "reverse_distance": 50,703 "subcategory": "LABEL",704 "category": "MUSIC",705 "template": "[[X]] released [[T]]",706 "distance": 30707 }708 },709 "infobox president": {710 "birth_place": {711 "reverse_distance": 50,712 "subcategory": "BIRTH",713 "category": "PERSON",714 "template": "[[T]] was born in [[X]]",715 "distance": 40716 },717 "occupation": {718 "reverse_distance": 80,719 "subcategory": "OCCUPATION",720 "category": "PERSON",721 "template": "[[T]] worked as a [[X]]",722 "distance": 30723 },724 "religion": {725 "reverse_distance": 70,726 "subcategory": "RELIGION",727 "category": "PERSON",728 "template": ["[[T]] is [[X]]", {r: "(ity)|(ism)|(lam)$", t: "[[T]]'s religion is [[X]]"}],729 "distance": 20730 },731 "spouse": {732 "reverse_distance": 10,733 "subcategory": "SPOUSE",734 "category": "GENEALOGICAL",735 "template": "[[T]] and [[X]] are married",736 "distance": 10737 }738 }739};740function page_is_ambiguous(title,page_json) {741 if (title.match(/\(disambiguation\)$/)) {742 return true;743 }744 for(var i=0, il=page_json.length; i < il; ++i) {745 var elem = page_json[i];746 if (typeof(elem) != 'string' && elem.type == 'template') {747 if (elem.title == 'disambig' || elem.title == 'disambiguation') {748 return true;749 }750 }751 }752 return false;753}754source_name = 'Wikipedia';755/* Lowercase and remove underscores to normalize template names */756function keyify(template_title) {757 return template_title.toLowerCase().replace("_"," ");758}759/* Do a replacement on the snippet */760function snippet_substitute(template,t,x) {761 if (typeof(template) != 'string') {762 var i;763 for (i=template.length-1; i > 0; --i) {764 var r = new RegExp(template[i].r);765 if (r.test(x)) {766 template = template[i].t;767 break;768 }769 }770 if (i == 0) {771 template = template[0];772 }773 }774 var res = template.replace("[[T]]",'[['+t+']]').replace("[[X]]",'[['+x+']]');775 if (!res.match(/[\.\?!]$/)) { res += '.'; }776 return res;777}778function do_top_level_field(in_value, out_hash, out_field) {779 if (in_value) {780 if (typeof(in_value) != 'string') {781 in_value = String(in_value);782 }783 if (in_value.match(/\S/)) {784 //out_hash[out_field] = clean_string(in_value);785 out_hash[out_field] = in_value;786 }787 }788}789/*790 * If a page is a redirect we want to emit an alias type791 */792function handle_redirect(key,redirect, output) {793 if (redirect.target) {794 Meguro.emit(redirect.target,JSON.stringify({'alias':key}));795 }796}797/*798 * Pull all of the internal links out of the param value of an infobox799 */800function pull_internal_links_out_of_param_value(param_val) {801 var internal_links = [];802 if (param_val.type == 'internal_link') {803 internal_links.push(param_val.target);804 } else {805 for(var i=0; i < param_val.length; i++) {806 var sec = param_val[i];807 if (sec.type == 'internal_link') {808 internal_links.push(sec.target);809 }810 }811 }812 return internal_links;813}814/*815 * Here we want to look through all the attributes of the Infobox and make816 * edges based on those817 */818function handle_template(key,template) {819 if (template.title) {820 var template_key = keyify(template.title);821 var rules = ATTRIBUTE_RULES[template_key];822 if (rules) {823 var params = template.parameters;824 for (var param_name in params) {825 var rule = rules[param_name];826 if (rule) {827 var param_val = params[param_name];828 var internal_links = pull_internal_links_out_of_param_value(param_val);829 if (internal_links.length > 0) {830 var snippet = snippet_substitute(rule.template,key,internal_links[0]);831 emit_relation(key, internal_links[0], rule.category, rule.subcategory, snippet, rule.distance, rule.reverse_distance);832 }833 }834 }835 }836 }837}838function emit_relation(key, target, category, subcategory, snippet, distance, reverse_distance) {839 var ed = new Object();840 ed.name = target;841 ed.relationship_category = category;842 ed.relationship_subcategory = subcategory;843 ed.snippet = snippet;844 ed.distance = distance;845 ed.source_name = 'Wikipedia';846 ed.source_URL = 'http://en.wikipedia.org/wiki/'+encodeURIComponent(key);847 Meguro.emit(key,JSON.stringify({"relation":ed}));848 // Now make the reverse edge849 var reverse_key = ed.name;850 ed.name = key;851 ed.distance = reverse_distance;852 Meguro.emit(reverse_key,JSON.stringify({"relation":ed}));853}854/*855 * Iterate through the elemnts looking for links and if the anchor text or the856 * target matches the cleaned title, then we emit an alias for that target857 * pointing to the title.858 */859function handle_ambiguous_page(title,json) {860 var title_name = (title.charAt(0)=='(' ? title : title.replace(/\s*\(.+\)/,''));861 for(var i=0, len = json.length; i < len; ++i) {862 var elem = json[i];863 if (typeof(elem) != 'string' && elem.type == 'internal_link') {864 if ((elem.anchor_text && elem.anchor_text.indexOf(title) >= 0) || elem.target.indexOf(title) >= 0) {865 Meguro.emit(elem.target,JSON.stringify({'alias':title_name}));866 } 867 }868 }869}870function map(key,value) {871 if (key.match(/^Wikipedia:/)) { return; }872 var json = JSON.parse(value);873 if (!json) { return; }874 if (page_is_ambiguous(key,json)) {875 handle_ambiguous_page(key,json);876 return;877 }878 var output = {};879 var outlinks = [];880 var paragraph_so_far = '';881 var targets_in_sentence = [];882 var prev_sentence_end = -1;883 for(var i=0, il=json.length; i < il; ++i) {884 if (typeof(json[i]) == 'string') {885 var str = json[i];886 // first see if a sentence ender in here and do targets in that sentence (only if not too long already)887 if (targets_in_sentence && targets_in_sentence.length > 0) {888 if (paragraph_so_far.charAt(0) != ':' && paragraph_so_far.charAt(0) != '*') {889 var sentence_ending_arr = str.match(/^[^\n]*?[a-z\]][a-z\]]\./);890 if (sentence_ending_arr) {891 var snippet = paragraph_so_far + sentence_ending_arr[0];892 var commas_in_sentence = snippet.substr(prev_sentence_end+1).match(/[,;]/g);893 if (!commas_in_sentence || commas_in_sentence.length <= 4) { // not weird run-on sentence894 for (var j=0, jl=targets_in_sentence.length; j < jl; ++j) {895 emit_relation(key, targets_in_sentence[j], 'UNCLASSIFIED', 'UNCLASSIFIED', snippet, -1, -1);896 }897 targets_in_sentence = [];898 prev_sentence_end = snippet.lastIndexOf('.');899 }900 else { // give up on this paragraph901 targets_in_sentence = null;902 }903 }904 } else {905 targets_in_sentence = null;906 }907 }908 var ind = str.indexOf("\n");909 if (ind >= 0) { //finished paragraph910 if (ind > 0 || paragraph_so_far.length > 0) { // don't want to take just a single stray newline before we've got real text911 paragraph_so_far += str.substr(0, ind);912 if (!output.descriptions) { // means first paragraph913 output.descriptions = [];914 output.descriptions[0] = {};915 do_top_level_field(paragraph_so_far.replace(/\s?\([^\(\)]*\)/g,''), output.descriptions[0], 'text');916 do_top_level_field(source_name, output.descriptions[0], 'source_name');917 do_top_level_field('http://en.wikipedia.org/wiki/'+encodeURIComponent(key), output.descriptions[0], 'source_URL');918 }919 targets_in_sentence = [];920 var nline = str.lastIndexOf("\n");921 if (nline < 0) {922 nline = ind;923 }924 paragraph_so_far = str.substr(nline+1).replace(/^[\n\s]+/,'');925 prev_sentence_end = paragraph_so_far.lastIndexOf('.');926 } 927 } else {928 paragraph_so_far += str;929 }930 } else {931 switch (json[i].type) {932 case 'template':933 handle_template(key,json[i]);934 break;935 case 'redirect':936 handle_redirect(key,json[i], output);937 break;938 case 'internal_link':939 var link = json[i];940 if (targets_in_sentence) {941 targets_in_sentence.push(link.target);942 }943 if (link.anchor_text) {944 paragraph_so_far += '[['+link.target+'|'+link.anchor_text+']]';945 } else {946 paragraph_so_far += '[['+link.target+']]';947 }948 var saw_this_outlink = 0;949 for (var j=0, jl=outlinks.length; j < jl; ++j) {950 if (outlinks[j] == link.target) {951 saw_this_outlink = 1;952 break;953 }954 }955 if (!saw_this_outlink) {956 outlinks.push(link.target);957 //X Meguro.emit(link.target, JSON.stringify({inl:key}));958 }959 break;960 }961 }962 }963 if (output.descriptions) { //this isn't just a redirect964 do_top_level_field((key.charAt(0)=='(' ? key : key.replace(/\s*\(.+\)/,'')), output, 'common_name');965 Meguro.emit(key,JSON.stringify({about:output})); //Meguro.emit(key,JSON.stringify({about:output}, {outl:outlinks}));966 }967}968// ---------------------------------------------969// -------- R e d u c e r ----------------------970// ---------------------------------------------971/*972 * Make a final graph entry based on the different emitted values973 */974function reduce(key,values) {975 var is_not_just_alias = false;976 var output = {};977 // first go through array and figure out a hash of common inlink counts, also checking here that this is not an alias entry978 var outlinks_of_inlinks_counts = {};979 var inlinks_count = 1; // because count self as linking to self980 for (var i = 0, il=values.length; i < il; ++i) {981 if (values[i] == '') { continue; }982 var v = JSON.parse(values[i]);983 if (v.about) {984 v = v.about;985 for (var k in v) {986 output[k] = v[k];987 }988 is_not_just_alias = true;989 } else if (v.inl) {990 inlinks_count += 1;991 var dv = Meguro.dictionary(v.inl);992 if (!dv) { Meguro.log("no outlinks for "+v.inl); exit; }993 var outlinks_of_link = JSON.parse(dv); 994 for (var j = 0, jl=outlinks_of_link.length; j < jl; ++j) {995 var n = outlinks_of_link[j]; //a page linked to from a page that also links to key996 if (n != key) {997 outlinks_of_inlinks_counts[n] = (outlinks_of_inlinks_counts.hasOwnProperty(n) ? outlinks_of_inlinks_counts[n]+1 : 1);998 }999 }1000 }1001 }1002 if (!is_not_just_alias) {1003 return;1004 }1005 // also look at things this page itself links to1006 /*1007 var outlinks = Meguro.dictionary(key);1008 if (!outlinks) {1009 Meguro.log("No outlinks for "+key);1010 exit;1011 }1012 outlinks = JSON.parse(outlinks);1013 for (var i = 0, il=outlinks.length; i < il; ++i) {1014 var n = outlinks[i];1015 outlinks_of_inlinks_counts[n] = (outlinks_of_inlinks_counts.hasOwnProperty(n) ? outlinks_of_inlinks_counts[n]+1 : 1);1016 }1017 */1018 // now go through again and actually consider "about" information, edges, etc.1019 var output_edges = {};1020ITER:1021 for (var i = 0, il=values.length; i < il; ++i) {1022 if (values[i] == '') { continue; }1023 var v = JSON.parse(values[i]);1024 if (v.alias) {1025 if (!output.aliases) {1026 output.aliases = [v.alias];1027 } else {1028 if (output.aliases.indexOf(v.alias) < 0) {1029 output.aliases.push(v.alias);1030 }1031 }1032 } else if (v.relation) {1033 v = v.relation;1034 /*1035 if (v.distance < 0) {1036 v.distance = Math.round(245*(1-outlinks_of_inlinks_counts[v.name]/inlinks_count)) + 10;1037 }1038 */1039 var edge = null;1040 var desc_ind = null;1041 if (output_edges.hasOwnProperty(v.name)) {1042 edge = output_edges[v.name];1043 for (var j=0, jl=edge.descriptors.length; j < jl; ++j) {1044 var d = edge.descriptors[j];1045 if (d.relationship_category == v.relationship_category && d.relationship_subcategory == v.relationship_subcategory) {1046 if (d.relationship_category == 'UNCLASSIFIED') { // in-text1047 edge.descriptors[j].snippet = choose_snippet(d.snippet, v.snippet, v.name, key);1048 continue ITER;1049 }1050 if (d.distance <= v.distance) {1051 continue ITER; //already have descriptor worth keeping about this1052 }1053 desc_ind = j;1054 }1055 break;1056 }1057 if (desc_ind == null) { // no matching descriptor1058 desc_ind = edge.descriptors.length;1059 edge.descriptors.push({});1060 }1061 if (edge.distance > v.distance) {1062 edge.distance = v.distance;1063 }1064 } else { // new edge1065 edge = {"descriptors":[{}], "distance":v.distance};1066 output_edges[v.name] = edge;1067 desc_ind = 0;1068 }1069 for (var k in v) { 1070 if (k != 'name') {1071 edge.descriptors[desc_ind][k] = v[k];1072 }1073 }1074 } else if (!v.inl && !v.about) {1075 Meguro.log("Why unknown in reduce: "+v);1076 exit;1077 }1078 }1079 output.edges = output_edges;1080 var now = new Date();1081 output.last_updates = {};1082 output.last_updates[source_name] = now.toGMTString();1083 Meguro.save(key, JSON.stringify(output));1084}1085/* Given multiple snippets, choose the best one according to the shorter one that (ideally) mentions both concepts. */1086function choose_snippet(snippet1, snippet2, key1, key2) {1087 var key_a = convert_to_query(key1);1088 var pat1 = new RegExp(key_a, 'i');1089 key_a = convert_to_query(key2);1090 var pat2 = new RegExp(key_a, 'i');1091 var snippets = undefined;1092 if (snippet1.length < snippet2.length) {1093 snippets = [snippet1, snippet2];1094 } else {1095 snippets = [snippet2, snippet1];1096 }1097 /* first see if any of snippets contains both names */1098 for (var i = 0, il=snippets.length; i < il; ++i) {1099 var s = snippets[i];1100 if ((rel_match(s, key1) || s.match(pat1)) && (rel_match(s, key2) || s.match(pat2))) {1101 return snippets[i];1102 }1103 }1104 return snippets[0];1105}1106function rel_match(where, what) {1107 return (where.indexOf("[["+what+"|")>=0 || where.indexOf("[["+what+"]")>=0);1108}1109function convert_to_query(word) {1110 /* first, see if this might be a name (by seeing if 1-3 words in the "word" that are all capitalized... */1111 var parts = word.split(/\s+/);1112 var nparts = parts.length;1113 if (nparts > 1 && nparts < 5) {1114 var noncapital = 0;1115 for (var i = 0; i < nparts; ++i) {1116 if (!parts[i].match(/^[A-Z]/)) {1117 noncapital = 1;1118 break;1119 }1120 }1121 // if so, just look at last part1122 if (!noncapital && parts[nparts-1].length > 2) {1123 if (word.match(/\.$/)) {1124 word = parts[nparts-2].replace(/[,:;!]$/,'');1125 }1126 else if (parts.length > 3) {1127 word = parts[0]+' '+parts[1];1128 }1129 else if (parts[nparts-1] == 'University' || parts[nparts-1] == 'College') {1130 parts.pop();1131 word = parts.join(' ');1132 }1133 else {1134 word = parts[nparts-1];1135 }1136 }1137 }1138 return word.toLowerCase();...

Full Screen

Full Screen

reward_test.py

Source:reward_test.py Github

copy

Full Screen

...27 self.assertEqual(1, reward.mod_abs_diff(15, 4, 5))28 def testAbsoluteDistance_AbsDiffMethod(self):29 self.assertEqual(30 4,31 reward.absolute_distance([0], [4], 5, scalar_diff_fn=reward.abs_diff))32 self.assertEqual(33 0,34 reward.absolute_distance([4], [4], 5, scalar_diff_fn=reward.abs_diff))35 self.assertEqual(36 0,37 reward.absolute_distance([], [], 5, scalar_diff_fn=reward.abs_diff))38 self.assertEqual(39 5,40 reward.absolute_distance([1], [], 5, scalar_diff_fn=reward.abs_diff))41 self.assertEqual(42 5,43 reward.absolute_distance([], [1], 5, scalar_diff_fn=reward.abs_diff))44 self.assertEqual(45 0,46 reward.absolute_distance([1, 2, 3], [1, 2, 3], 5,47 scalar_diff_fn=reward.abs_diff))48 self.assertEqual(49 1,50 reward.absolute_distance([1, 2, 4], [1, 2, 3], 5,51 scalar_diff_fn=reward.abs_diff))52 self.assertEqual(53 1,54 reward.absolute_distance([1, 2, 2], [1, 2, 3], 5,55 scalar_diff_fn=reward.abs_diff))56 self.assertEqual(57 5,58 reward.absolute_distance([1, 2], [1, 2, 3], 5,59 scalar_diff_fn=reward.abs_diff))60 self.assertEqual(61 5,62 reward.absolute_distance([1, 2, 3, 4], [1, 2, 3], 5,63 scalar_diff_fn=reward.abs_diff))64 self.assertEqual(65 6,66 reward.absolute_distance([4, 4, 4], [1, 2, 3], 5,67 scalar_diff_fn=reward.abs_diff))68 def testAbsoluteDistance_ModDiffMethod(self):69 self.assertEqual(70 1,71 reward.absolute_distance([0], [4], 5,72 scalar_diff_fn=reward.mod_abs_diff))73 self.assertEqual(74 0,75 reward.absolute_distance([4], [4], 5,76 scalar_diff_fn=reward.mod_abs_diff))77 self.assertEqual(78 0,79 reward.absolute_distance([], [], 5,80 scalar_diff_fn=reward.mod_abs_diff))81 self.assertEqual(82 5,83 reward.absolute_distance([1], [], 5,84 scalar_diff_fn=reward.mod_abs_diff))85 self.assertEqual(86 5,87 reward.absolute_distance([], [1], 5,88 scalar_diff_fn=reward.mod_abs_diff))89 self.assertEqual(90 0,91 reward.absolute_distance([1, 2, 3], [1, 2, 3], 5,92 scalar_diff_fn=reward.mod_abs_diff))93 self.assertEqual(94 1,95 reward.absolute_distance([1, 2, 4], [1, 2, 3], 5,96 scalar_diff_fn=reward.mod_abs_diff))97 self.assertEqual(98 1,99 reward.absolute_distance([1, 2, 2], [1, 2, 3], 5,100 scalar_diff_fn=reward.mod_abs_diff))101 self.assertEqual(102 5,103 reward.absolute_distance([1, 2], [1, 2, 3], 5,104 scalar_diff_fn=reward.mod_abs_diff))105 self.assertEqual(106 5,107 reward.absolute_distance([1, 2, 3, 4], [1, 2, 3], 5,108 scalar_diff_fn=reward.mod_abs_diff))109 self.assertEqual(110 5,111 reward.absolute_distance([4, 4, 4], [1, 2, 3], 5,112 scalar_diff_fn=reward.mod_abs_diff))113 def testLogAbsoluteDistance(self):114 def log_diff(diff, base):115 return log(diff + 1) / log(base // 2 + 2)116 self.assertEqual(117 log_diff(1, 5),118 reward.log_absolute_distance([0], [4], 5))119 self.assertEqual(120 log_diff(2, 5),121 reward.log_absolute_distance([1], [4], 5))122 self.assertEqual(123 log_diff(2, 5),124 reward.log_absolute_distance([2], [4], 5))125 self.assertEqual(126 log_diff(1, 5),127 reward.log_absolute_distance([3], [4], 5))128 self.assertEqual(129 log_diff(3, 5), # max_dist = base // 2 + 1 = 3130 reward.log_absolute_distance([], [4], 5))131 self.assertEqual(132 0 + log_diff(3, 5), # max_dist = base // 2 + 1 = 3133 reward.log_absolute_distance([4, 4], [4], 5))134 self.assertEqual(135 0,136 reward.log_absolute_distance([4], [4], 5))137 self.assertEqual(138 0,139 reward.log_absolute_distance([], [], 5))140 self.assertEqual(141 1,142 reward.log_absolute_distance([1], [], 5))143 self.assertEqual(144 1,145 reward.log_absolute_distance([], [1], 5))146 self.assertEqual(147 0,148 reward.log_absolute_distance([1, 2, 3], [1, 2, 3], 5))149 self.assertEqual(150 log_diff(1, 5) / 3, # divided by target length.151 reward.log_absolute_distance([1, 2, 4], [1, 2, 3], 5))152 self.assertEqual(153 log_diff(1, 5) / 3,154 reward.log_absolute_distance([1, 2, 2], [1, 2, 3], 5))155 self.assertEqual(156 log_diff(3, 5) / 3, # max_dist157 reward.log_absolute_distance([1, 2], [1, 2, 3], 5))158 self.assertEqual(159 log_diff(3, 5) / 3, # max_dist160 reward.log_absolute_distance([1, 2, 3, 4], [1, 2, 3], 5))161 # Add log differences for each position.162 self.assertEqual(163 (log_diff(2, 5) + log_diff(2, 5) + log_diff(1, 5)) / 3,164 reward.log_absolute_distance([4, 4, 4], [1, 2, 3], 5))165 def testAbsoluteDistanceReward(self):166 self.assertEqual(167 1,168 reward.absolute_distance_reward([1, 2, 3], [1, 2, 3], 5))169 self.assertEqual(170 1 - 1 / (5 * 3.), # 1 - distance / (base * target_len)171 reward.absolute_distance_reward([1, 2, 4], [1, 2, 3], 5))172 self.assertEqual(173 1 - 1 / (5 * 3.),174 reward.absolute_distance_reward([1, 2, 2], [1, 2, 3], 5))175 self.assertTrue(np.isclose(176 1 - 5 / (5 * 3.),177 reward.absolute_distance_reward([1, 2], [1, 2, 3], 5)))178 self.assertTrue(np.isclose(...

Full Screen

Full Screen

DistanceOp.js

Source:DistanceOp.js Github

copy

Full Screen

...146 if (arguments[2] instanceof Array && (arguments[0] instanceof LineString && arguments[1] instanceof Point)) {147 const line = arguments[0]148 const pt = arguments[1]149 const locGeom = arguments[2]150 if (line.getEnvelopeInternal().distance(pt.getEnvelopeInternal()) > this._minDistance) return null151 const coord0 = line.getCoordinates()152 const coord = pt.getCoordinate()153 for (let i = 0; i < coord0.length - 1; i++) {154 const dist = CGAlgorithms.distancePointLine(coord, coord0[i], coord0[i + 1])155 if (dist < this._minDistance) {156 this._minDistance = dist157 const seg = new LineSegment(coord0[i], coord0[i + 1])158 const segClosestPoint = seg.closestPoint(coord)159 locGeom[0] = new GeometryLocation(line, i, segClosestPoint)160 locGeom[1] = new GeometryLocation(pt, 0, coord)161 }162 if (this._minDistance <= this._terminateDistance) return null163 }164 } else if (arguments[2] instanceof Array && (arguments[0] instanceof LineString && arguments[1] instanceof LineString)) {165 const line0 = arguments[0]166 const line1 = arguments[1]167 const locGeom = arguments[2]168 if (line0.getEnvelopeInternal().distance(line1.getEnvelopeInternal()) > this._minDistance) return null169 const coord0 = line0.getCoordinates()170 const coord1 = line1.getCoordinates()171 for (let i = 0; i < coord0.length - 1; i++) {172 for (let j = 0; j < coord1.length - 1; j++) {173 const dist = CGAlgorithms.distanceLineLine(coord0[i], coord0[i + 1], coord1[j], coord1[j + 1])174 if (dist < this._minDistance) {175 this._minDistance = dist176 const seg0 = new LineSegment(coord0[i], coord0[i + 1])177 const seg1 = new LineSegment(coord1[j], coord1[j + 1])178 const closestPt = seg0.closestPoints(seg1)179 locGeom[0] = new GeometryLocation(line0, i, closestPt[0])180 locGeom[1] = new GeometryLocation(line1, j, closestPt[1])181 }182 if (this._minDistance <= this._terminateDistance) return null183 }184 }185 }186 }187 }188 computeMinDistancePoints (points0, points1, locGeom) {189 for (let i = 0; i < points0.size(); i++) {190 const pt0 = points0.get(i)191 for (let j = 0; j < points1.size(); j++) {192 const pt1 = points1.get(j)193 const dist = pt0.getCoordinate().distance(pt1.getCoordinate())194 if (dist < this._minDistance) {195 this._minDistance = dist196 locGeom[0] = new GeometryLocation(pt0, 0, pt0.getCoordinate())197 locGeom[1] = new GeometryLocation(pt1, 0, pt1.getCoordinate())198 }199 if (this._minDistance <= this._terminateDistance) return null200 }201 }202 }203 distance () {204 if (this._geom[0] === null || this._geom[1] === null) throw new IllegalArgumentException('null geometries are not supported')205 if (this._geom[0].isEmpty() || this._geom[1].isEmpty()) return 0.0206 this.computeMinDistance()207 return this._minDistance208 }209 computeMinDistanceLines (lines0, lines1, locGeom) {210 for (let i = 0; i < lines0.size(); i++) {211 const line0 = lines0.get(i)212 for (let j = 0; j < lines1.size(); j++) {213 const line1 = lines1.get(j)214 this.computeMinDistance(line0, line1, locGeom)215 if (this._minDistance <= this._terminateDistance) return null216 }217 }218 }219 interfaces_ () {220 return []221 }222 getClass () {223 return DistanceOp224 }225 static distance (g0, g1) {226 const distOp = new DistanceOp(g0, g1)227 return distOp.distance()228 }229 static isWithinDistance (g0, g1, distance) {230 const distOp = new DistanceOp(g0, g1, distance)231 return distOp.distance() <= distance232 }233 static nearestPoints (g0, g1) {234 const distOp = new DistanceOp(g0, g1)235 return distOp.nearestPoints()236 }...

Full Screen

Full Screen

dtw.js

Source:dtw.js Github

copy

Full Screen

...99 state.m,100 state.n,101 Number.POSITIVE_INFINITY102 );103 distanceCostMatrix[0][0] = state.distance(s[0], t[0]);104 for (var rowIndex = 1; rowIndex < state.m; rowIndex++) {105 var cost = state.distance(s[rowIndex], t[0]);106 distanceCostMatrix[rowIndex][0] =107 cost + distanceCostMatrix[rowIndex - 1][0];108 }109 for (var columnIndex = 1; columnIndex < state.n; columnIndex++) {110 var cost = state.distance(s[0], t[columnIndex]);111 distanceCostMatrix[0][columnIndex] =112 cost + distanceCostMatrix[0][columnIndex - 1];113 }114 for (var rowIndex = 1; rowIndex < state.m; rowIndex++) {115 for (var columnIndex = 1; columnIndex < state.n; columnIndex++) {116 var cost = state.distance(s[rowIndex], t[columnIndex]);117 distanceCostMatrix[rowIndex][columnIndex] =118 cost +119 Math.min(120 distanceCostMatrix[rowIndex - 1][columnIndex],121 distanceCostMatrix[rowIndex][columnIndex - 1],122 distanceCostMatrix[rowIndex - 1][columnIndex - 1]123 );124 }125 }126 const end = new Date().getTime();127 const time = end - start;128 debug("< computeOptimalPath (" + time + " ms)");129 state.distanceCostMatrix = distanceCostMatrix;130 state.similarity = distanceCostMatrix[state.m - 1][state.n - 1];131 return state.similarity;132}133function computeOptimalPathWithWindow(s, t, w, state) {134 debug("> computeOptimalPathWithWindow");135 validateComputeParameters(s, t);136 const start = new Date().getTime();137 state.m = s.length;138 state.n = t.length;139 const window = Math.max(w, Math.abs(s.length - t.length));140 let distanceCostMatrix = matrix.create(141 state.m + 1,142 state.n + 1,143 Number.POSITIVE_INFINITY144 );145 distanceCostMatrix[0][0] = 0;146 for (let rowIndex = 1; rowIndex <= state.m; rowIndex++) {147 for (148 let columnIndex = Math.max(1, rowIndex - window);149 columnIndex <= Math.min(state.n, rowIndex + window);150 columnIndex++151 ) {152 const cost = state.distance(s[rowIndex - 1], t[columnIndex - 1]);153 distanceCostMatrix[rowIndex][columnIndex] =154 cost +155 Math.min(156 distanceCostMatrix[rowIndex - 1][columnIndex],157 distanceCostMatrix[rowIndex][columnIndex - 1],158 distanceCostMatrix[rowIndex - 1][columnIndex - 1]159 );160 }161 }162 const end = new Date().getTime();163 const time = end - start;164 debug("< computeOptimalPathWithWindow (" + time + " ms)");165 distanceCostMatrix.shift();166 distanceCostMatrix = distanceCostMatrix.map((row) => {...

Full Screen

Full Screen

Spiralcell_minicaster.py

Source:Spiralcell_minicaster.py Github

copy

Full Screen

1#Define variables2printvel_left = 4 #printvel3printvel_right = 4 #printvel 4printvel_fill = 4 #printvel 5tipsize = 0.200 #tipsize; mm 6layerheight = 0.8*tipsize #stepheight; mm 7layers = 1 #layers8COM = 4 #air-line 9pressure_left= 70 #air-pressure,psi 10pressure_right= 70 #air-pressure,psi 11pressure_fill= 70 #air-pressure,psi 12leadin = 3 #leadinx; mm 13edge = 5 #outer-wall-side-length; mm 14spacing = 0.05 #middle-wall-side-length; mm 15def spiral_left(edge, tipsize, spacing):16 #starts from middle left17 g.set_home(x=0,y=0,Z=0)18 g.feed(printvel_left)19 g.move(x=-leadin)20 g.set_pressure(COM, pressure_left)21 g.toggle_pressure(COM)22 g.dwell(3)23 g.move(x=leadin)24 25 g.move(y=edge/2-tipsize/2) #from halfway to starting corner26 distance = edge-tipsize*2-spacing27 g.move(x=distance) #1st horizontal line28 g.move(y=-distance) #1st vertical line29 while distance >= 3*tipsize:30 31 distance = distance-tipsize*2-spacing*232 33 g.move(x=-distance)34 g.move(y=distance)35 36 if distance >= 3*tipsize:37 distance = distance-tipsize*2-spacing*238 39 g.move(x=distance)40 g.move(y=-distance)41 42 g.toggle_pressure(COM)43 g.dwell(5)44 g.move(Z=3)45def spiral_right(edge, tipsize, spacing):46 #starts from middle right47 g.set_home(x=0,y=0,Z=0)48 g.feed(printvel_right)49 g.move(x=leadin)50 g.set_pressure(COM, pressure_right)51 g.toggle_pressure(COM)52 g.dwell(3)53 g.move(x=-leadin)54 55 g.move(y=-(edge/2-tipsize/2)) #from halfway to starting corner56 distance = edge-tipsize*2-spacing57 g.move(x=-distance) #1st horizontal line58 g.move(y=distance) #1st vertical line59 while distance >= 3*tipsize:60 61 distance = distance-tipsize*2-spacing*262 63 g.move(x=distance)64 g.move(y=-distance)65 66 if distance >= 3*tipsize:67 distance = distance-tipsize*2-spacing*268 69 g.move(x=-distance)70 g.move(y=distance)71 g.toggle_pressure(COM)72 g.dwell(5)73 g.move(Z=3)74 75def spiral_fill(edge, tipsize, spacing):76 g.set_home(x=0,y=0,Z=0)77 g.feed(printvel_fill)78 79 for i in range (int(tipsize/spacing)+1):80 #starts from middle left, under spiral left's start81 g.abs_move(x=0,y=0)82 g.move(x=-(leadin+tipsize/2+spacing/2)) 83 g.set_pressure(COM, pressure_fill)84 g.toggle_pressure(COM)85 g.dwell(3)86 g.move(x=leadin+tipsize/2+spacing/2)87 88 g.move(y=edge/2-tipsize/2) #from halfway to starting corner89 distance = edge-tipsize*3-spacing*290 g.move(x=distance) #1st horizontal line91 g.move(y=-distance) #1st vertical line92 while distance >= 3*tipsize:93 94 distance = distance-tipsize*2-spacing*295 96 g.move(x=-distance)97 g.move(y=distance)98 99 if distance >= 3*tipsize:100 distance = distance-tipsize*2-spacing*2101 102 g.move(x=distance)103 g.move(y=-distance)104 105 g.toggle_pressure(COM)106 g.dwell(5)107 g.move(Z=3)108 109 g.abs_move(x=edge-tipsize*2-spacing)110 g.move(Z=-3)111 112 #starts from middle right, under spiral left's start113 g.move(x=(leadin+tipsize/2+spacing/2)) 114 g.set_pressure(COM, pressure_fill)115 g.toggle_pressure(COM)116 g.dwell(3)117 g.move(x=-(leadin+tipsize/2+spacing/2))118 119 g.move(y=-(edge/2-tipsize/2)) #from halfway to starting corner120 distance = edge-tipsize*3-spacing*2121 g.move(x=-distance) #1st horizontal line122 g.move(y=distance) #1st vertical line123 while distance >= 3*tipsize:124 125 distance = distance-tipsize*2-spacing*2126 127 g.move(x=distance)128 g.move(y=-distance)129 130 if distance >= 3*tipsize:131 distance = distance-tipsize*2-spacing*2132 133 g.move(x=-distance)134 g.move(y=distance)135 g.toggle_pressure(COM)136 g.dwell(5)137 g.move(Z=spacing)138 g.move(Z=3)139 140 141from mecode import G142g = G(143 outfile = "/Users/SeanWei/Documents/Python/PrintCode/spiralcell/Spiralcell_left.txt",144 header = "/Users/SeanWei/Documents/Python/PrintCode/header_minicaster.txt",145 footer = "/Users/SeanWei/Documents/Python/PrintCode/footer_minicaster.txt",146 aerotech_include = False,147 direct_write = False,148 print_lines = True, 149 )150spiral_left(edge, tipsize, spacing)151from mecode import G152g = G(153 outfile = "/Users/SeanWei/Documents/Python/PrintCode/spiralcell/Spiralcell_right.txt",154 header = "/Users/SeanWei/Documents/Python/PrintCode/header_minicaster.txt",155 footer = "/Users/SeanWei/Documents/Python/PrintCode/footer_minicaster.txt",156 aerotech_include = False,157 direct_write = False,158 print_lines = True, 159 )160spiral_right(edge, tipsize, spacing)161from mecode import G162g = G(163 outfile = "/Users/SeanWei/Documents/Python/PrintCode/spiralcell/Spiralcell_fill.txt",164 header = "/Users/SeanWei/Documents/Python/PrintCode/header_minicaster.txt",165 footer = "/Users/SeanWei/Documents/Python/PrintCode/footer_minicaster.txt",166 aerotech_include = False,167 direct_write = False,168 print_lines = True, 169 )170spiral_fill(edge, tipsize, spacing)171#To end172g.view(backend='matplotlib')173#g.view()...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var differencify = require('differencify');2var differencify = new differencify({3});4differencify.setup({5});6differencify.run(function() {7 differencify.screenshot('test', function(err, result) {8 if (err) {9 console.log(err);10 } else {11 console.log('Distance: ' + result.distance);12 }13 });14});15differencify.run(function() {16 differencify.screenshot('test', function(err, result) {17 if (err) {18 console.log(err);19 } else {20 console.log('Distance: ' + result.distance);21 }22 });23});24differencify.setup(options)25differencify.run(callback)26differencify.screenshot(name, callback)

Full Screen

Using AI Code Generation

copy

Full Screen

1var differencify = require('differencify');2console.log(differencify.distance('kitten', 'sitting'));3var differencify = require('differencify');4console.log(differencify.distance('kitten', 'sitting'));5var differencify = require('differencify');6console.log(differencify.distance('kitten', 'sitting'));7var differencify = require('differencify');8console.log(differencify.distance('kitten', 'sitting'));9var differencify = require('differencify');10console.log(differencify.distance('kitten', 'sitting'));11var differencify = require('differencify');12console.log(differencify.distance('kitten', 'sitting'));13var differencify = require('differencify');14console.log(differencify.distance('kitten', 'sitting'));15var differencify = require('differencify');16console.log(differencify.distance('kitten', 'sitting'));17var differencify = require('differencify');18console.log(differencify.distance('kitten', 'sitting'));19var differencify = require('differencify');20console.log(differencify.distance('kitten', 'sitting'));

Full Screen

Using AI Code Generation

copy

Full Screen

1var differencify = require('differencify');2var differencify = new differencify();3differencify.distance('test1.png', 'test2.png', function(err, distance) {4 console.log(distance);5});6var differencify = require('differencify');7var differencify = new differencify();8differencify.distance('test1.png', 'test2.png', function(err, distance) {9 console.log(distance);10});

Full Screen

Using AI Code Generation

copy

Full Screen

1var differencify = require('differencify');2var differencify = new differencify();3var distance = differencify.distance('foo', 'bar');4console.log(distance);5var differencify = require('differencify');6var differencify = new differencify();7var diff = differencify.diff('foo', 'bar');8console.log(diff);9var differencify = require('differencify');10var differencify = new differencify();11var match = differencify.match('foo', 'bar');12console.log(match);13var differencify = require('differencify');14var differencify = new differencify();15var match = differencify.match('foo', 'bar', {threshold: 0.5});16console.log(match);17var differencify = require('differencify');18var differencify = new differencify();19var match = differencify.match('foo', 'bar', {threshold: 0.5, caseSensitive: true});20console.log(match);21var differencify = require('differencify');22var differencify = new differencify();23var match = differencify.match('foo', 'bar', {threshold: 0.5, caseSensitive: true, trim: true});24console.log(match);25var differencify = require('differencify');26var differencify = new differencify();27var match = differencify.match('foo', 'bar', {threshold: 0.5, caseSensitive: true, trim: true, ignorePunctuation: true});28console.log(match);29var differencify = require('differencify');30var differencify = new differencify();31var match = differencify.match('foo', 'bar', {threshold: 0.5, caseSensitive

Full Screen

Using AI Code Generation

copy

Full Screen

1var differencify = require('differencify');2var diff = new differencify({});3 console.log(data);4});5var differencify = require('differencify');6var diff = new differencify({});7 console.log(data);8});9var differencify = require('differencify');10var diff = new differencify({});11 console.log(data);12});13var differencify = require('differencify');14var diff = new differencify({});15 console.log(data);16});17var differencify = require('differencify');18var diff = new differencify({});19 console.log(data);20});21var differencify = require('differencify');22var diff = new differencify({});23 console.log(data);24});25var differencify = require('differencify

Full Screen

Using AI Code Generation

copy

Full Screen

1var differencify = require('differencify');2var differencify = differencify({3});4differencify.distance(function (err, result) {5 console.log(result);6});7{8 "scripts": {9 },10 "dependencies": {11 }12}13{ isSameDimensions: true,14 dimensionDifference: { width: 0, height: 0 },

Full Screen

Using AI Code Generation

copy

Full Screen

1var differencify = require('differencify');2var diff = new differencify();3diff.distance('test/fixtures/test1.png', 'test/fixtures/test2.png', function(err, data){4 if(err) throw err;5 console.log(data);6});7{ distance: 0.0001,8 dimensionDifference: { width: 0, height: 0 },9 getBuffer: [Function] }10var differencify = require('differencify');11var diff = new differencify();12diff.distance('test/fixtures/test1.png', 'test/fixtures/test2.png', function(err, data){13 if(err) throw err;14 data.getBuffer(function(err, buffer){15 if(err) throw err;16 console.log(buffer);17 });18});

Full Screen

Using AI Code Generation

copy

Full Screen

1var differencify = require('differencify');2var differ = differencify();3differ.distance('Hello World', 'Hello World', function(err, distance) {4});5var differencify = require('differencify');6var differ = differencify();7differ.distance('Hello World', 'Hello World', function(err, distance) {8});9var differencify = require('differencify');10var differ = differencify();11differ.distance('Hello World', 'Hello World', function(err, distance) {12});13var differencify = require('differencify');14var differ = differencify();15differ.distance('Hello World', 'Hello World', function(err, distance) {16});

Full Screen

Using AI Code Generation

copy

Full Screen

1var differencify = require('differencify');2differencify.setConfig({3});4differencify.init();5differencify.init({6});7differencify.compare({8});9differencify.compare({10}, function(err, result) {11});12differencify.compare({13}).then(function(result) {14});15differencify.compare({16}).then(function(result) {17}).catch(function(err) {18});19differencify.compare({20}).then(function(result) {21}).catch(function(err) {22}).finally(function(result) {23});24differencify.compare({25}, function(err, result) {26}).then(function(result) {27}).catch(function(err) {28}).finally(function(result) {29});30differencify.compare({31}, function(err, result) {32}).then(function(result) {33}).catch(function(err) {34});35differencify.compare({36}, function(err, result) {37}).then(function(result) {38});39differencify.compare({40}).then(function(result) {41}).catch(function(err) {42});43differencify.compare({44}).then(function(result) {45});46differencify.compare({47}, function(err, result) {48});49differencify.compare({50}).then(function(result) {51}).catch(function(err) {52});53differencify.compare({54}).then(function(result) {55});56differencify.compare({57}, function(err, result) {58});59differencify.compare({60}).then(function(result) {61});62differencify.compare({

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run differencify automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful